Closed tecosaur closed 6 years ago
https://github.com/James-Yu/LaTeX-Workshop/commit/213002b3ba2b1b1464f2b60d67a78096ddbb53ff Wasn't this commit supposed to address this? The name of the commit suggests yes
I like this request a lot
Seems like I've probably spent a while writing out a request for a feature that already exists 😛. Now time to try out the stuff in that commit.
@tecosaur Thing is I don't know how you try it because there are no keybindings for the commands provided
I've tried:
F1
Insert Snippet
FEM
Enter
However that just overwrites the selection with \emph{}
I've tried the above steps exactly as shown and can get the correct result. Anyone may provide a screencast on the problematic behavior?
I'm getting correct results too with the steps u described @tecosaur However in light of this Issue, I think it will be nice to implement CTRL+B/Bold CTRL+I/Italics etc...
Also I don't think binding CTRL+B is an issue because in vscode you can add the when
clause which in our case will be to trigger the command only when a text is selected.
Here's a demo of it not working. After you said it worked for you though, I tried it on my other computer and it worked ¯\_(ツ)_/¯.
I didn't know the when
clause could be applied to text selection, if it can I think adding stuff like Ctrl
+B
would be a worthwhile addition!
I have some ideas for improving them / adding more (math mode etc.). So I may create a pull request doing that.
@tecosaur What's that theme if you don't mind me asking? 😁
@Astrantia It may be off topic, but here's how I have my editor (visually) set up.
I use Monokai Pro and just ignore the 'Pay for me' prompts, then I've also installed the font Fira Code and enabled ligatures. Highlights come from this extension, and then I also use Bracket Pair Colorizer. End result, the editor looks like this:
@James-Yu Do you know if it's possible to have a when
clause for text/math mode?
Also looking to see if there's a keybindings file, and if not what one would have to do to get one working.
Have added more formatting things: see here Also written and tested shortcuts (see below).
{
"key": "ctrl+b",
"when": "editorHasSelection && editorLangId == 'latex'",
"command": "editor.action.insertSnippet",
"args": {
"name": "textbf"
}
},
{
"key": "ctrl+i",
"when": "editorHasSelection && editorLangId == 'latex'",
"command": "editor.action.insertSnippet",
"args": {
"name": "textit"
}
},
{
"key": "ctrl+u",
"when": "editorHasSelection && editorLangId == 'latex'",
"command": "editor.action.insertSnippet",
"args": {
"name": "underline"
}
},
{
"key": "ctrl+e",
"when": "editorHasSelection && editorLangId == 'latex'",
"command": "editor.action.insertSnippet",
"args": {
"name": "textem"
}
},
{
"key": "ctrl+t",
"when": "editorHasSelection && editorLangId == 'latex'",
"command": "editor.action.insertSnippet",
"args": {
"name": "texttt"
}
}
Actually, this feature already existed in the extension. It was broken, but I have just fixed it.
\
Note: if you use the vim-mode
, it only works in insert
mode, not in visual
one.
@jlelong While that is good, to me it doesn't quite seem to fully address what's being discussed here. While it may not be a life-changing addition, what I was thinking of was something more like this: So far this uses some of a commit I made to my fork of this repo (this) and the shortcuts pasted earlier.
I recently stumbled across https://latextools.readthedocs.io/en/latest/keybindings/ and ftp://ftp.gnu.org/gnu/auctex/11.89-extra/tex-ref.pdf - some bits may be good food for thought. I'd definitely be interested in implementing some select keybindings.
Isn't this a dupe of #434?
@Swoy Why close #434 though? I understand it an be configured manually, but it will be easier if all the configurations are shipped by the extension. For example, the most popular markdown editor ships with CTRL+B mapping to *{selection}*
, etc...
I'm considering renaming and rewriting this issue, or starting a new issue - since (at least in my mind) this seems to have evolved beyond just font emphasis (really only since I discovered the documents linked in my earlier reply - and as a result, my LaTeX-workshop-keyboard-shortcut horizons have been expanded).
Re: Keyboard Shortcuts
I recently stumbled across https://latextools.readthedocs.io/en/latest/keybindings/ and ftp://ftp.gnu.org/gnu/auctex/11.89-extra/tex-ref.pdf - some bits may be good food for thought. I'd definitely be interested in implementing some select keybindings.
@James-Yu question that will be repeated in the new issue: Do you know if there's a way to use a when
clause to differentiate between text and math mode?
(asking now because you seem to be online, and I'm still writing that issue up)
@tecosaur I have no idea on such a when
condition unfortunately 😢
How is it defined to use separate syntax highlighting etc. compared to normal in the extension? And what sort of terms are used when registering it with VS Code? I'm basically looking for good keywords to use for online searching.
@jlelong Expert in syntax highlighting. Lemme ping him for you. 🤣
Also, does anybody know of any extensions that have keyboard shortcuts that only work when you're working in certain parts of the file?
I do not think it is possible to restrict a keybinding to parts of a file. See here for the list of when clause. Getting the scope at the current character already seems to be a problem: vscode#15287 and vscode#18485.
Oh well, from what you linked it looks like a scope filter isn't likely to be around any time soon :( Thanks for investigating it.
I guess we can close this issue and continue chatting on #809 concerning how to add keybindings to the existing snippets.
Idea
This isn't something I feel particularly strongly about, however, it is definitely something that I would appreciate.
It would be nice if LaTeX workshop had the ability to apply
\textbf{...}
,\emp{...}
, to selected text - ideally with different rules for text/math mode.Why?
Because while it's not a huge amount of effort adding tags around selected text manually,
Three Ideas for Implementation
Ordered from least versitile to most versitile.
Simple Shortcuts
Since
Ctrl+B
is already bound, perhapsAlt+B/I/…
would be a better alternative.Two-part Shortcuts
Or one of those two key hotkeys (i.e. '
Ctrl+K Ctrl+C
') - which would then better allow for all the text variants latex has, i.e. After an initial key combo, the "Single Key" from the table below would trigger the appropriate wrapping/unwrappingCommand Palate
Shortcut for a new command such as "Modify Text Style", which when selected would give an array of options, that can be searched and selected, with hardcoded selections based on the "Single Key" and "Two Key" columns of the table below. I'd imagine this would feel similar to that unicode character searching extension to use.
The Aforementioned Table
n
no
\textnormal{...}
\mathnormal{...}
e
em
\emph{...}
r
rm
\textrm{...}
\mathrm{...}
b
bf
\textbf{...}
\mathbf{...}
bb
\mathbb{...}
i
it
\textit{...}
\mathit{...}
sl
\textsl{...}
t
tt
\texttt{...}
c
sc
\textsc{...}
c
ca
\mathcal{...}
s
sf
\textsf{...}
u
up
\uppercase{...}
l
lo
\lowercase{...}
How much of an improvement is this really?
Apart from
\emph
and\textbf
I know I don't use many of those other ones frequently,and when applying\emph
to a section of text it's not too hard, but because it's done frequently enough I would definitely appreciate the effort-saving. Example:{
→ left arrow →\
→e
→m
→ enteralt
→e
R
→{
→\
→m
→a
→t
→h
→b
→ enterR
→ Shortcut →b
→b
→ enterNot life-changing, but appreciable.
Final Note(s)