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

feature: search paste support #881

Merged
merged 7 commits into from
Nov 10, 2022
Merged

feature: search paste support #881

merged 7 commits into from
Nov 10, 2022

Conversation

ClementTsang
Copy link
Owner

@ClementTsang ClementTsang commented Nov 9, 2022

Description

A description of the change, what it does, and why it was made. If relevant (such as any change that modifies the UI), please provide screenshots of the changes:

Adds paste support to the process search bar.

Unix support is primarily implemented using paste events. Windows falls back to keyboard inputs; to support this, I removed the key event throttler since it doesn't really seem to be necessary anymore.

This also fixes a potential issue of the grapheme cursor increment occasionally failing if it doesn't have enough context - luckily, the unicode library has a fix for that.

Issue

If applicable, what issue does this address?

Closes: #880

Testing

If relevant, please state how this was tested. All changes must be tested to work:

If this is a code change, please also indicate which platforms were tested:

  • Windows
  • macOS
  • Linux

Checklist

If relevant, ensure the following have been met:

  • Areas your change affects have been linted using rustfmt (cargo fmt)
  • The change has been tested and doesn't appear to cause any unintended breakage
  • Documentation has been added/updated if needed (README.md, help menu, doc pages, etc.)
  • The pull request passes the provided CI pipeline
  • There are no merge conflicts
  • If relevant, new tests were added (don't worry too much about coverage)

Supports pasting events to the search bar (e.g. shift-insert, ctrl-shift-v).
@codecov-commenter
Copy link

codecov-commenter commented Nov 9, 2022

Codecov Report

Base: 18.55% // Head: 18.41% // Decreases project coverage by -0.13% ⚠️

Coverage data is based on head (17a6c12) compared to base (5f849e8).
Patch coverage: 0.81% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #881      +/-   ##
==========================================
- Coverage   18.55%   18.41%   -0.14%     
==========================================
  Files          74       74              
  Lines       13698    13800     +102     
==========================================
  Hits         2541     2541              
- Misses      11157    11259     +102     
Impacted Files Coverage Δ
src/app.rs 0.00% <0.00%> (ø)
src/app/widgets/process_table.rs 0.00% <0.00%> (ø)
src/lib.rs 6.16% <0.00%> (-0.13%) ⬇️
src/bin/main.rs 37.43% <10.00%> (-1.74%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment on lines 779 to 840
let chunk = &self.proc_search.search_state.current_search_query[start_position..];

match self
.proc_search
.search_state
.grapheme_cursor
.next_boundary(
&self.proc_search.search_state.current_search_query[start_position..],
start_position,
)
.unwrap();
.next_boundary(chunk, start_position)
{
Ok(_) => {}
Err(err) => match err {
GraphemeIncomplete::PreContext(ctx) => {
// Provide the entire string as context. Not efficient but should resolve failures.
self.proc_search
.search_state
.grapheme_cursor
.provide_context(
&self.proc_search.search_state.current_search_query[0..ctx],
0,
);

self.proc_search
.search_state
.grapheme_cursor
.next_boundary(chunk, start_position)
.unwrap();
}
_ => Err(err).unwrap(),
},
}
}

pub fn search_walk_back(&mut self, start_position: usize) {
self.proc_search
let chunk = &self.proc_search.search_state.current_search_query[..start_position];
match self
.proc_search
.search_state
.grapheme_cursor
.prev_boundary(
&self.proc_search.search_state.current_search_query[..start_position],
0,
)
.unwrap();
.prev_boundary(chunk, 0)
{
Ok(_) => {}
Err(err) => match err {
GraphemeIncomplete::PreContext(ctx) => {
// Provide the entire string as context. Not efficient but should resolve failures.
self.proc_search
.search_state
.grapheme_cursor
.provide_context(
&self.proc_search.search_state.current_search_query[0..ctx],
0,
);

self.proc_search
.search_state
.grapheme_cursor
.prev_boundary(chunk, 0)
.unwrap();
}
_ => Err(err).unwrap(),
},
}
Copy link
Owner Author

@ClementTsang ClementTsang Nov 10, 2022

Choose a reason for hiding this comment

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

A very quick-and-dirty way to properly fix grapheme boundary determination.

Note to self: add tests for this in the future.

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

Successfully merging this pull request may close these issues.

[Feature] Add pasting into search bar
2 participants