Vscode-bookmarks: Use selected text as current label

Created on 9 Oct 2019  路  6Comments  路  Source: alefragnani/vscode-bookmarks

Is it possible to use selected text as label for new bookmarks (if selected text is a one-line)? Such feature would allow faster bookmarking of functions, classes, .. etc.

Suggested use-case:

  1. Select function/class name
  2. Press "Ctrl + Alt + k" to bookmark and instantly use the selected text as label

Old use case:

  1. Select function/class name
  2. Press "Ctrl-C" to copy name
  3. Press bookmark short cut "Ctrl + Alt + k" to bookmark
  4. Click on bookmarks icon in activity bar
  5. Find the bookmark, right click it, and choose "Edit label"
  6. Paste the function/class name

New flow makes it easier to bookmark with meaningful labels while focusing on code. Specially when the beginning of the line isn't very meaningful text. For instance you can come through a long line like that in C++ file:
std::unordered_map<unsigned int, std::vector<std::vector<int>> ClassName::FunctionName()

It becomes essential to rename this bookmark to "FunctionName" to be able to spot it easily in the bookmarks sidebar.

enhancement

All 6 comments

Hi @ogamal ,

Thank you for your suggestion 馃憤 . I don鈥檛 use labeled bookmarks, but I agree it鈥檚 a great improvement.

But, I wouldn鈥檛 change the _default_ Toggle bookmark command to use the selected text, but instead, make the Toggle Labeled to use it. BTW, I鈥檓 not sure you know about it, because in your _Old use case_ scenario, you used the Side Bar to label the bookmark. Also, it would have a setting to define this behavior (default on).

Hope this helps

@alefragnani I didn't know about Toggle Labeled. That's useful in my use-case and saves few steps. It would be great if it is possible to make it default and even better if it can populate from selected text.

Thanks,

@alefragnani I didn't know about Toggle Labeled. That's useful in my use-case and saves few steps

That鈥檚 great!

It would be great if it is possible to make it default and even better if it can populate from selected text.

That鈥檚 the idea. In fact, I鈥檓 thinking about:

  • Don鈥檛 use (like today)
  • Suggest (as you asked)
  • Use (automatic)

It would fulfill _any_ scenario 馃槵

@alefragnani Sounds great!

My two cents on how it could be implemented:

  • Toggle Labeled should prefill the label's textbox with the selected text if there is any.
  • Toggle Labeled should prefill the label's textbox with the code of the current line if nothing is selected.
  • And in both of the cases above the prefilled text in the textbox should be preselected so that I could start entering my own new custom label in case I am not interested in the prefilled text.

Based on your feedback, I designed 4 possible suggestions. Choose the one better fit your needs, and define it in Preferences: Settings

  • dontUse: Don't use the selection (original behavior - default value)
  • useWhenSelected: Use the selected text _(if available)_ directly, no confirmation required
  • suggestWhenSelected: Suggests the selected text _(if available)_. You still need to confirm.
  • suggestWhenSelectedOrLineWhenNoSelected: Suggests the selected text _(if available)_ or the entire line (when has no selection). You still need to confirm
    "bookmarks.label.suggestion": "useWhenSelected"

This feature should be released this weekend.

Stay tuned

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LighghtEeloo picture LighghtEeloo  路  6Comments

vannie1 picture vannie1  路  3Comments

jayarjo picture jayarjo  路  6Comments

jing2si picture jing2si  路  4Comments

zpaolo11x picture zpaolo11x  路  3Comments