feat: Cursor Placement Setting & Behavior When Bookmarking#876
feat: Cursor Placement Setting & Behavior When Bookmarking#876metal-gabe wants to merge 12 commits into
Conversation
…metal-gabe/vscode-bookmarks into cursor-placement-setting
alefragnani
left a comment
There was a problem hiding this comment.
Hi @metal-gabe ,
As discussed in the issue, I would take a different approach. So, the changes in controller could be reverted. You should take a closer look at revealPosition in src/utils/reveal.ts file (since it handles all navigation);list in src/extension.ts and listBookmarks in src/core/operations.ts since it is used by Command Palette and Side Bar to display the bookmarks and their previews.
Let'me know if you need any help
| "%bookmarks.configuration.confirmClear.enumDescriptions.sideBar%" | ||
| ] | ||
| }, | ||
| "bookmarks.cursorPosition": { |
There was a problem hiding this comment.
As discussed in the issue, I would take a different approach. And the settings would have a slight different id/options too.
bookmarks.navigation.columnMode
"stored"(default) — current behavior, cursor lands at stored column"lineStart"— always go to column 0"firstNonWhitespace"— go to first non-whitespace character"lineEnd"— go to end of line
There was a problem hiding this comment.
@alefragnani alright, the feature has been updated with this new approach
please let me know how everything looks!
alefragnani
left a comment
There was a problem hiding this comment.
Hi @metal-gabe ,
First of all, sorry for the late reply, and thanks for the update in the PR.
I was able to test it, and it seems to be almost perfect. I noticed two small issues, and would like you to address it.
- 1. Behavior regression in cursor restore flow: Since
revelPositionnow always rewrites the target column via navigation.columnMode, when the user cancels the quick-picks fromBookmarks: ListandBookmarks: List from All Filescommands, the cursor does not return to the original position, but instead, goes to the position defined in thebookmarks.navigation.columnModesetting. I would suggest adding an optional param torevealPositionfunction that when set, jump reveal the exact location. Something like:
export function revealPosition(line: number, column: number, directJump?: boolean): void {
if (isNaN(column)) {
revealLine(line);
} else {
const resolvedColumn = directJump ? column : resolveNavigationColumn(line, column);
...And, in extension.ts on both list() and listFromAllFiles() functions, when selection === undefined, the revealPosition should use directJump as true.
- 2. Localization missed for other languages: The new entries in
package.jsonshould be added to other (than english) languages as well.
Thank you
Add
bookmarks.cursorPositionsettingIntroduces a new configuration setting,
bookmarks.cursorPosition, that controls which column position is stored when a bookmark is created.New setting:
bookmarks.cursorPositioncurrentPosition(default)lineStart0(the very start of the line)contentStartcontentEndChanges
package.json— Registers the newbookmarks.cursorPositionconfiguration contribution with its enum values and descriptions.package.nls.json— Adds localization keys for the new setting's description and all enum option descriptions.src/core/controller.ts— Adds aresolveColumnprivate method that reads the setting and computes the appropriate column value at bookmark creation time. Both labeled and unlabeled bookmark paths now useresolveColumninstead ofposition.characterdirectly. The method opens the text document to inspect line content when needed, with a fallback to the active editor.Note