Skip to content

Any way to extend CodeMirror's "showInCenter" to bring a line to the top? #1792

Answered by tophf
dmland asked this question in Q&A
Discussion options

You must be logged in to vote

The workaround for the current editing session would be to run the following code in devtools:

CodeMirror.commands.showCurLineAtTop = cm => cm.scrollTo(null, cm.cursorCoords(null, 'local').top);
CodeMirror.defaults.extraKeys['Alt-T'] = 'showCurLineAtTop';

Alt is physically the Opt key in Mac. Note that ⌘T can't be used in a shortcut as it's a built-in browser key, unless you also use navigator.keyboard.lock(), but that's not supported in Firefox/Safari, which is why we don't use it in general.

I think this is trivial and possibly useful enough for me to include the command in Stylus, but I'd like to check those suggestions you mentioned first as there may be some useful nuance. If you wan…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dmland
Comment options

Answer selected by dmland
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants