-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Support matching for selected text #4502
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,7 +266,12 @@ class FindMode extends Mode { | |
} | ||
|
||
// Returns null if no search has been performed yet. | ||
static getQuery(backwards) { | ||
static getQuery(backwards, query) { | ||
if (query) { | ||
this.query = {}; | ||
this.updateQuery(query); | ||
this.saveQuery(); | ||
} | ||
if (!this.query) return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we don't want to replace |
||
// check if the query has been changed by a script in another frame | ||
const mostRecentQuery = FindModeHistory.getQuery(); | ||
|
@@ -358,9 +363,9 @@ class FindMode extends Mode { | |
return FindMode.saveQuery(); | ||
} | ||
|
||
static findNext(backwards) { | ||
static findNext(backwards, query) { | ||
// Bail out if we don't have any query text. | ||
const nextQuery = FindMode.getQuery(backwards); | ||
const nextQuery = FindMode.getQuery(backwards, query); | ||
if (!nextQuery) { | ||
HUD.show("No query to find.", 1000); | ||
return; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,6 +213,18 @@ const NormalModeCommands = { | |
} | ||
}, | ||
|
||
findSelected() { | ||
let selection = window.getSelection().toString(); | ||
if (!selection) return; | ||
return FindMode.findNext(false, selection); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we do want to avoid passing in a query (see comments above), then we can add the two lines above this return.
As you found, to fix the undefined object error, we also need to add an initialization to the start or the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, it is a better approach. Thanks! |
||
}, | ||
|
||
findSelectedBackwards() { | ||
let selection = window.getSelection().toString(); | ||
if (!selection) return; | ||
return FindMode.findNext(true, selection); | ||
}, | ||
|
||
// Misc. | ||
mainFrame() { | ||
return focusThisFrame({ highlight: true, forceFocusThisFrame: true }); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since both
query
andthis.query
have similar names, it will be confusing in the future what each represents. I think it would be helpful to add a quick comment here to explain the difference and why we need this.A possible suggestion, based in my understanding of your implementation, might be:
// Update the this.query if we are passed in a selection query parameter
However, see my next comment to potentially change this implementation, in which case, the comment wouldn't be needed.