-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
Picks up the highlighted text for file search #194906
Picks up the highlighted text for file search #194906
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
@TylerLeonhardt also as October has started, I was wondering if can we add hacktoberfest-accepted label to this when all looks good? 😃 |
@nikhilkarve you don't have to worry about updating the branch. That's not a blocker for merging. Also, I marked the PR as |
} | ||
|
||
// only happen if it would also happen for the search view | ||
const seedSearchStringFromSelection = configurationService.getValue<boolean>('editor.find.seedSearchStringFromSelection'); |
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.
We should have our own setting. Follow what we did for preserveInput
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.
Got it, added that! Great suggestion @TylerLeonhardt . Let me know if that's correct! Thanks
btw, I opened these two issues on the quickTextSearch #194675 and #194835 see if you experience these same bugs in your code as well. If you do, can you fix them in your code please 🙏 I want to merge this PR in without those same bugs. Also, if you figure out those bugs in your code... you can send us 2 additional PRs fixing the bugs in the quickTextSearch too giving you more hacktoberfest PRs :) if you're interested. |
Sure, I would be more than happy to take a look at those issues as well. No problem, I was anyways looking for anymore issues where I can contribute. |
@TylerLeonhardt Sir if you could add more issues under hactoberfest label, then it would be very benificial for new contributors like me. |
@@ -382,6 +382,11 @@ configurationRegistry.registerConfiguration({ | |||
'description': nls.localize('search.experimental.quickAccess.preserveInput', "Controls whether the last typed input to Quick Search should be restored when opening it the next time."), | |||
'default': false | |||
}, | |||
'search.experimental.quickAccess.seedFileSearchStringFromSelection': { |
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.
I don't think this needs to be an experimental setting. I think search.quickOpen.seedStringFromSelection
should be sufficient.
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.
Got it, will update that
@@ -382,6 +382,11 @@ configurationRegistry.registerConfiguration({ | |||
'description': nls.localize('search.experimental.quickAccess.preserveInput', "Controls whether the last typed input to Quick Search should be restored when opening it the next time."), | |||
'default': false | |||
}, | |||
'search.experimental.quickAccess.seedFileSearchStringFromSelection': { | |||
'type': 'boolean', | |||
'description': nls.localize('search.experimental.quickAccess.seedFileSearchStringFromSelection', "Controls whether the search string in the Search File Widget is seeded from the editor selection."), |
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.
Instead of Search File Widget
, we should use Quick Open
.
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.
Got it will change
Hi @andreamah I pushed the changes as per your comment. Let me know if that is correct, otherwise I will push what's required asap |
export function getFileSelectionTextFromEditor(allowUnselectedWord: boolean, editor: IEditor): string | null { | ||
|
||
if (!isCodeEditor(editor) || !editor.hasModel()) { | ||
return null; | ||
} | ||
|
||
const range = editor.getSelection(); | ||
if (!range) { | ||
return null; | ||
} | ||
|
||
if (range.isEmpty()) { | ||
if (allowUnselectedWord) { | ||
const wordAtPosition = editor.getModel().getWordAtPosition(range.getStartPosition()); | ||
return wordAtPosition?.word ?? null; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
let searchText = ''; | ||
for (let i = range.startLineNumber; i <= range.endLineNumber; i++) { | ||
let lineText = editor.getModel().getLineContent(i); | ||
if (i === range.endLineNumber) { | ||
lineText = lineText.substring(0, range.endColumn - 1); | ||
} | ||
|
||
if (i === range.startLineNumber) { | ||
lineText = lineText.substring(range.startColumn - 1); | ||
} | ||
|
||
if (i !== range.startLineNumber) { | ||
lineText = '\n' + lineText; | ||
} | ||
|
||
searchText += lineText; | ||
} | ||
|
||
return searchText; | ||
} |
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.
just noticed this, but I think that
vscode/src/vs/workbench/contrib/search/browser/searchView.ts
Lines 2143 to 2192 in a7a4d6a
export function getSelectionTextFromEditor(allowUnselectedWord: boolean, activeEditor: IEditor): string | null { | |
let editor = activeEditor; | |
if (isDiffEditor(editor)) { | |
if (editor.getOriginalEditor().hasTextFocus()) { | |
editor = editor.getOriginalEditor(); | |
} else { | |
editor = editor.getModifiedEditor(); | |
} | |
} | |
if (!isCodeEditor(editor) || !editor.hasModel()) { | |
return null; | |
} | |
const range = editor.getSelection(); | |
if (!range) { | |
return null; | |
} | |
if (range.isEmpty()) { | |
if (allowUnselectedWord) { | |
const wordAtPosition = editor.getModel().getWordAtPosition(range.getStartPosition()); | |
return wordAtPosition?.word ?? null; | |
} else { | |
return null; | |
} | |
} | |
let searchText = ''; | |
for (let i = range.startLineNumber; i <= range.endLineNumber; i++) { | |
let lineText = editor.getModel().getLineContent(i); | |
if (i === range.endLineNumber) { | |
lineText = lineText.substring(0, range.endColumn - 1); | |
} | |
if (i === range.startLineNumber) { | |
lineText = lineText.substring(range.startColumn - 1); | |
} | |
if (i !== range.startLineNumber) { | |
lineText = '\n' + lineText; | |
} | |
searchText += lineText; | |
} | |
return searchText; | |
} |
has pretty much the same code, but also makes sure to get text from diff editors. Can you reuse that?
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.
I tried that earlier, I get the following error if I do that while committing
Imports violates 'vs/css!.//* or vs/base/{common,browser}/ or vs/base/parts//{common,browser}/** or vs/platform//{common,browser}/** or vs/editor/{common,browser}/** or vs/editor/contrib//{common,browser}/** or vs/workbench/{common,browser}/** or vs/workbench/services//{common,browser}/** or assert or vs/nls or vs/amdX' restrictions.
Its not letting me import anything from the contrib folder.
https://github.com/microsoft/vscode/wiki/Source-Code-Organization
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.
One way I can think of is writing this function somewhere, probably a folder from which is import is allowed. And then reusing it in both the places. Not sure exactly where though. Are there any conventions?
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.
I'm okay with this code living in quickaccess.ts
as long as you have the most up-to-date version of the function (including the newest changes from today).
@TylerLeonhardt are you okay with the selection-grabbing code being here and search just importing it? Ideally, the selection code could be somewhere else more communal in the future and be shared by everything that gets editor selection.
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.
Shall I import the function from quickaccess.ts to searchView.ts then? I think this import is possible. I can change the function name from getFileSelectionTextFromEditor to getSelectionTextFromEditor
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.
Yes, the function would only occur once in quickAccess.ts
. Make sure that you have the part
if (isDiffEditor(editor)) {
if (editor.getOriginalEditor().hasTextFocus()) {
editor = editor.getOriginalEditor();
} else {
editor = editor.getModifiedEditor();
}
}
Since it looks like your current implementation doesn't have it and it's needed to get the selection in diff editors.
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.
Sure, I will add that too
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.
Yes I think having this in quickaccess.ts
for this and search to use makes sense.
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.
I updated the PR with those changes, let me know if this is correct!
looks good! one more thing: can you resolve the merge conflicts with main? |
* Add sessionId, agent, and slash command to core telemetry * Enable used references by default
Fix used references expand state
Add chat agent header animation
…cue loop from continuing"
…t-response Revert "accept chat response when session is released, prevent audio cue loop from continuing"
* aux window - disable main menu * 💄
…del content change
Adopt documentOverride in xterm.js
Start moving window/document to use layout service
Allow hiding of launcher on Run and Debug title bar when debugging
Add agent avatar icon and "using @workspace" text
Show Reload Required buttons simultaneously after updateAllExtensions (#163627)
Terminal: fix rename and injection
Add multi-select renames to terminalAction
Pass terminal context to relevant actions
Layout when switching from welcome to terminal.
There are a lot of conflicts not sure why. Is it okay if I create a new branch from the current main and create a new PR? |
Creating a new PR is totally ok :) |
@TylerLeonhardt @andreamah |
Fixes #194573