Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle _selected_range sent to NSTextInputClient.setMarkedText(). #3619

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

ShikiSuen
Copy link

  • Tested on all platforms changed // Only macOS.
  • Added an entry to the changelog module if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality
  • Updated feature matrix, if new features were added or implemented

This only solves the _selected_range part of this issue: #3617

@ShikiSuen
Copy link
Author

Some CI typo checks might need improvements...

Copy link
Member

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've been thinking about using these values as well in the past, but ended up forgetting about it exactly because the UTF-16 to UTF-8 conversion was a bit tricky, and I was lazy ;).

src/platform_impl/macos/view.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/view.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/view.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/view.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/view.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/view.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/view.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/view.rs Outdated Show resolved Hide resolved
@ShikiSuen
Copy link
Author

ShikiSuen commented Apr 3, 2024

Thanks to @pan93412 and @madsmtm 's suggestions. Most of these suggestions are applied on the GitHub webpage, hence the spammed commit history. I apologize if that brings any inconvenience.

image

@ShikiSuen
Copy link
Author

Memo: I'm revising the sanity check of the get_actual_range_bounds().
Maybe Pan misunderstood my intention here. I need to add some more inline commments.

@ShikiSuen
Copy link
Author

The revision is done. I guess this PR is ready for merge.
Or we can wait for @madsmtm's refactor commit if he is glad to provide one.

P.S.: I just don't know how to handle the Id<T> in Rust...

@pan93412
Copy link

pan93412 commented Apr 3, 2024

It may be better to squash all the commits in this PR to one.

@ShikiSuen
Copy link
Author

@pan93412 Thanks. Squashed.

This PR needs to be force-pulled due to the force-pushed suqashed commit. cc @madsmtm

@ShikiSuen ShikiSuen requested a review from madsmtm April 5, 2024 03:45
src/platform_impl/macos/view.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/view.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/view.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/view.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/view.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/view.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/view.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/view.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/view.rs Outdated Show resolved Hide resolved
Copy link
Member

@kchibisov kchibisov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kchibisov
Copy link
Member

Besides the @madsmtm review. You should pass the CI (use nightly formatter).

@ShikiSuen
Copy link
Author

@kchibisov
image

@pan93412
Copy link

pan93412 commented May 4, 2024

@kchibisov

image

You should install it with rustup toolchain install nightly: https://rust-lang.github.io/rustup/concepts/channels.html

@ShikiSuen
Copy link
Author

@pan93412 Sry but seems too late. Something seems to be permanently crapped on my computer due to the installation of the nightly.

I dunno why depending on nightly CI utilities for stability-critical scenarios.

~/Repos/winit > cargo install rustfmt-nightly                                           05/04/2024 02:00:22 PM
    Updating crates.io index
  Downloaded rustfmt-nightly v1.4.21
  Downloaded 1 crate (519.2 KB) in 1.53s
error: binary `cargo-fmt` already exists in destination
binary `rustfmt` already exists in destination
Add --force to overwrite
~/Repos/winit > cargo +nightly fmt                                                      05/04/2024 02:00:28 PM
error: toolchain 'nightly-x86_64-apple-darwin' is not installed
~/Repos/winit > cargo install rustfmt-nightly --force                                   05/04/2024 02:00:36 PM
    Updating crates.io index
  Installing rustfmt-nightly v1.4.21
    Updating crates.io index
  Downloaded autocfg v1.3.0
  Downloaded byte-tools v0.3.1
  Downloaded block-padding v0.1.5
  Downloaded vec_map v0.8.2
  Downloaded fake-simd v0.1.2
  Downloaded opaque-debug v0.2.3
  Downloaded block-buffer v0.7.3
  Downloaded ansi_term v0.11.0
  Downloaded arrayvec v0.5.2
  Downloaded dirs-sys v0.3.7
  Downloaded dirs v2.0.2
  Downloaded digest v0.8.1
  Downloaded fastrand v2.1.0
  Downloaded humantime v1.3.0
  Downloaded lock_api v0.3.4
  Downloaded ena v0.14.2
  Downloaded generic-array v0.12.4
  Downloaded derive-new v0.5.9
  Downloaded rustc-ap-rustc_lexer v677.0.0
  Downloaded rustc-ap-rustc_feature v677.0.0
  Downloaded psm v0.1.21
  Downloaded semver v0.9.0
  Downloaded scoped-tls v1.0.1
  Downloaded textwrap v0.11.0
  Downloaded thiserror-impl v1.0.59
  Downloaded stacker v0.1.15
  Downloaded synstructure v0.12.6
  Downloaded unicode-xid v0.2.4
  Downloaded unicode-width v0.1.12
  Downloaded semver-parser v0.7.0
  Downloaded anyhow v1.0.82
  Downloaded env_logger v0.6.2
  Downloaded quick-error v1.2.3
  Downloaded maybe-uninit v2.0.0
  Downloaded parking_lot_core v0.6.3
  Downloaded quote v1.0.36
  Downloaded memmap v0.7.0
  Downloaded thiserror v1.0.59
  Downloaded tracing-attributes v0.1.27
  Downloaded proc-macro2 v1.0.81
  Downloaded ignore v0.4.22
  Downloaded typenum v1.17.0
  Downloaded structopt v0.3.26
  Downloaded toml v0.5.11
  Downloaded serde v1.0.200
  Downloaded itertools v0.8.2
  Downloaded unicode_categories v0.1.1
  Downloaded cc v1.0.96
  Downloaded rustc-ap-rustc_parse v677.0.0
  Downloaded unicode-normalization v0.1.23
  Downloaded serde_derive v1.0.200
  Downloaded serde_json v1.0.116
  Downloaded clap v2.34.0
  Downloaded rustc-rayon v0.3.2
  Downloaded syn v2.0.60
  Downloaded rustix v0.38.34
  Downloaded term v0.6.1
  Downloaded rustc-ap-rustc_target v677.0.0
  Downloaded rustc-ap-rustc_data_structures v677.0.0
  Downloaded rustc-ap-rustc_ast v677.0.0
  Downloaded rustc-ap-rustc_expand v677.0.0
  Downloaded rustfmt-config_proc_macro v0.2.0
  Downloaded rustc-workspace-hack v1.0.0
  Downloaded rustc-ap-rustc_span v677.0.0
  Downloaded rustc-ap-rustc_serialize v677.0.0
  Downloaded rustc-ap-rustc_macros v677.0.0
  Downloaded rustc-ap-rustc_index v677.0.0
  Downloaded rustc-ap-rustc_graphviz v677.0.0
  Downloaded rustc-ap-rustc_fs_util v677.0.0
  Downloaded rustc-ap-rustc_errors v677.0.0
  Downloaded rustc-ap-rustc_attr v677.0.0
  Downloaded rustc-ap-rustc_ast_pretty v677.0.0
  Downloaded rustc-ap-rustc_ast_passes v677.0.0
  Downloaded rustc-ap-rustc_arena v677.0.0
  Downloaded parking_lot_core v0.7.3
  Downloaded measureme v0.7.1
  Downloaded md-5 v0.8.0
  Downloaded libc v0.2.154
  Downloaded cargo_metadata v0.8.2
  Downloaded bstr v1.9.1
  Downloaded annotate-snippets v0.6.1
  Downloaded rustc-rayon-core v0.3.2
  Downloaded rustc-ap-rustc_session v677.0.0
  Downloaded smallvec v0.6.14
  Downloaded diff v0.1.13
  Downloaded crossbeam-utils v0.7.2
  Downloaded crossbeam-epoch v0.9.18
  Downloaded annotate-snippets v0.8.0
  Downloaded parking_lot v0.10.2
  Downloaded parking_lot v0.9.0
  Downloaded jobserver v0.1.31
  Downloaded globset v0.4.14
  Downloaded either v1.11.0
  Downloaded termize v0.1.1
  Downloaded termcolor v1.4.1
  Downloaded rustc_version v0.2.3
  Downloaded structopt-derive v0.4.18
  Downloaded strsim v0.8.0
  Downloaded sha-1 v0.8.2
  Downloaded crossbeam-deque v0.8.5
  Downloaded bytecount v0.6.8
  Downloaded 101 crates (5.1 MB) in 1.54s
   Compiling proc-macro2 v1.0.81
   Compiling unicode-ident v1.0.12
   Compiling libc v0.2.154
   Compiling serde v1.0.200
   Compiling syn v1.0.109
   Compiling semver-parser v0.7.0
   Compiling autocfg v1.3.0
   Compiling cfg-if v0.1.10
   Compiling crossbeam-utils v0.8.19
   Compiling cc v1.0.96
   Compiling maybe-uninit v2.0.0
   Compiling typenum v1.17.0
   Compiling scopeguard v1.2.0
   Compiling lazy_static v1.4.0
   Compiling byteorder v1.5.0
   Compiling smallvec v1.13.2
   Compiling log v0.4.21
   Compiling smallvec v0.6.14
error[E0554]: `#![feature]` may not be used on the stable release channel
  --> /Users/shikisuen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/smallvec-1.13.2/src/lib.rs:96:37
   |
96 | #![cfg_attr(feature = "may_dangle", feature(dropck_eyepatch))]
   |                                     ^^^^^^^^^^^^^^^^^^^^^^^^

   Compiling lock_api v0.3.4
   Compiling hashbrown v0.12.3
error[E0557]: feature has been removed
  --> /Users/shikisuen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lock_api-0.3.4/src/lib.rs:91:42
   |
91 | #![cfg_attr(feature = "nightly", feature(const_fn))]
   |                                          ^^^^^^^^ feature has been removed
   |
   = note: split into finer-grained feature gates

For more information about this error, try `rustc --explain E0554`.
error: could not compile `smallvec` (lib) due to previous error
warning: build failed, waiting for other jobs to finish...
For more information about this error, try `rustc --explain E0557`.
error: could not compile `lock_api` (lib) due to previous error
error: failed to compile `rustfmt-nightly v1.4.21`, intermediate artifacts can be found at `/var/folders/10/6wq7rrd57qx334gglsl_cfs00000gq/T/cargo-installghlNPo`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
~/Repos/winit >                                                                         05/04/2024 02:00:45 PM

@ShikiSuen
Copy link
Author

@pan93412 I managed to install the nightly toolchain but still got this after running cargo fmt.

I can't understand why we have to waste time on unstable toolchains.

image

@ShikiSuen
Copy link
Author

@kchibisov The nightly rustfmt hinders the TODO to be in a standalone line. Is there a way to stop the nightly rustfmt from doing this stupid?

image

@pan93412
Copy link

pan93412 commented May 4, 2024

@pan93412 I managed to install the nightly toolchain but still got this after running cargo fmt.

I can't understand why we have to waste time on unstable toolchains.

To pick up the nightly toolchain, run cargo +nightly fmt. You can switch your default toolchain to nightly by running rustup default nightly.

Some Rust users prefer the nightly toolchain, as it contains features that significantly improve the DX or are critical for some purposes. I also use nightly for my personal projects.

@kchibisov
Copy link
Member

@ShikiSuen please, mind your language, even though it seems like you've deleted/edited a bunch of replies, it doesn't mean that I haven't seen them. This is not the first time when you behave impulsive, which may be off putting for certain people.

Some Rust users prefer the nightly toolchain, as it contains features that significantly improve the DX or are critical for some purposes. I also use nightly for my personal projects.

Stable rustfmt can not do good formatting unfortunately and it's like that for a very long time. As you can see, we use nightly only for fmt, and not for anything else.

If you have major issues with formatting, you should politely ask that you can not do that, instead of exaggerating.

@kchibisov
Copy link
Member

The nightly rustfmt hinders the TODO to be in a standalone line. Is there a way to stop the nightly rustfmt from doing this stupid?

The general rule is to separate paragraphs with a blank line. I also don't like TODO in code in general, but it's up to @madsmtm to complain about such things, since it's not my backend.

@ShikiSuen
Copy link
Author

ShikiSuen commented May 4, 2024

@kchibisov

If I were you, I'll clearly write these things in README.md prior to ask the contributor to use cargo-fmt:

  1. Requirements about nightly toolchain and nightly cargo-fmt.
  2. Detailed instructions regarding how to install and run them to help stable-only Rust users to stay on the right track.

What I experienced today is of extreme frustration.

I got blamed by those users of my input method app
... because of all IMKTextInput client apps written in Rust directly or indirectly using this package.
... And I come here trying to fix the problem here to stop being blamed by my users.

And what I have experienced here today is totally unfair to me.

I'm sorry for what you have said "impulsive", but I really need to take a break.

(You might have felt something else impulsive from my previous comments. That's all because I got blamed by something that is technically not my fault... Especially the buggy InputMethodKit in macOS.)

@ShikiSuen
Copy link
Author

@kchibisov
I added the formatting policy to the README.md through this PR:
#3680

@kchibisov
Copy link
Member

Detailed instructions regarding how to install and run them to help stable-only Rust users to stay on the right track.

The rust itself does educate on how to install the toolchains and we don't require a particular nightly, etc, it's just any nightly. Though, there's no section in CONTRIBUTING.md that nighly needed, indeed.

And what I have experienced here today is totally unfair to me.

The thing is that this PR is not delayed because of new formatting change or anything like that, it's delayed because I want @madsmtm to look into it, and he is busy recently, even though I pinged him here numerous times. If PR is ready I'd just handle conflicts myself and merged on my own which is what I always do anyway, when I don't like something. It's just given that you decided to rebase recently, I decided to acknowledge that you in general should make your PR green (if they issue is on you on indicate that you don't know what to do).

I got blamed by those users of my input method app... because of all IMKTextInput client apps written in Rust directly or indirectly using this package.... And I come here trying to fix the problem here to stop being blamed by my users.

If users are blaming you for such thing, I'd just ignore them, because you don't owe anything them, unless you provide a paid service for them. Then it's a bit a different matter. Like I understand that it could be hard if you're not experienced dealing with that, but you can not please everyone.

In this particular case you send a patch and then it's really not your problem anymore.

(You might have felt something else impulsive from my previous comments. That's all because I got blamed by something that is technically not my fault... Especially the buggy InputMethodKit in macOS.)

It's a matter of the words you're using and how you react to things during the review, and it's not a language barrier or anything, because you need some knowledge to speak like that. Unless you've learned English by only talking in gaming discords or something, idk.

But besides all of that, keep in mind that winit in the end of the day is an open source project and we do that in our free time. I know that @madsmtm is not MIA, if they were, I'd handle that PR myself. Which requires more time from me than I want, etc, because I just don't like macOS in general.

@ShikiSuen
Copy link
Author

(Re-review requests sent, conforming to the contribution guidelines.)

@kchibisov
Copy link
Member

(Re-review requests sent, conforming to the contribution guidelines.)

I mean, there's no need to ask for re-review given that review was not submitted in the first place...

Copy link
Member

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a commit to simplify the implementation, the extra function wasn't really required especially when I changed the way we got the string (there was some extra round-tripping between &str and NSString that wasn't necessary). Additionally I removed the sanity check, the range is documented to be in bounds, and Foundation is just going to throw an exception if it wasn't (i.e. it's not unsound to pass a wrong index).

Thanks @ShikiSuen, and apologies I didn't get to this sooner.

@ShikiSuen
Copy link
Author

I agree with Madsmtm's amendment.
Is there anything unfinished prior to merging this PR?

@ShikiSuen
Copy link
Author

i.e. it's not unsound to pass a wrong index

Looks like it is just my lack of familiarity with Foundation working on programming languages other than Swift. In Swift it is always an asserted death if an out-of-bound index gets passed into an array.

@kchibisov
Copy link
Member

Swift it is always an asserted death if an out-of-bound index gets passed into an array.

yet, it's still fine to do so in swift, it'll just assert the same way. unsound would mean that safe code invokes undefined behavior, panic is not unsound.

@ShikiSuen
Copy link
Author

Swift it is always an asserted death if an out-of-bound index gets passed into an array.

yet, it's still fine to do so in swift, it'll just assert the same way. unsound would mean that safe code invokes undefined behavior, panic is not unsound.

Yes. What I want to say is that in such situation Swift doesn't throw an Exception for devs to handle. It just crashes instead. The generated IPS crash report in macOS console indicates that it is caused by array-out-of-bounds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

5 participants