Edit style: use 'sublime' keymap, add custom keys

F3, Shift-F3, Ctrl-H - find/find previous/replace
Ctrl-G: go to line dialog
Alt-PgDn: next code section
Alt-PgUp: previous code section
...and many more.
This commit is contained in:
9adefaf01e5bf6426d838cd20eae582d2b6ba647 2015-03-05 09:39:09 +03:00
parent 1c7eaa6903
commit 20123760ac
3 changed files with 24 additions and 0 deletions

View File

@ -92,6 +92,10 @@
"message": "Disable",
"description": "Label for the button to disable a style"
},
"editGotoLine": {
"message": "Goto line (or line:col)",
"description": "Go to line or line:column on Ctrl-G in style code editor"
},
"editStyleHeading": {
"message": "Edit Style",
"description": "Title of the page for editing styles"

View File

@ -29,6 +29,8 @@
<script src="codemirror/addon/hint/show-hint.js"></script>
<script src="codemirror/addon/hint/css-hint.js"></script>
<script src="codemirror/keymap/sublime.js"></script>
<style type="text/css">
body {

18
edit.js
View File

@ -25,8 +25,26 @@ function setupCodeMirror(textarea) {
matchBrackets: true,
lint: CodeMirror.lint.css,
smartIndent: prefs.getPref("smart-indent"),
keyMap: "sublime",
extraKeys: {"Ctrl-Space": "autocomplete"}
});
cm.addKeyMap({
"Ctrl-G": function(cm) {
var cur = cm.getCursor();
cm.openDialog(t('editGotoLine') + ': <input type="text" style="width: 5em"/>', function(str) {
var m = str.match(/^\s*(\d+)(?:\s*:\s*(\d+))?\s*$/);
if (m) {
cm.setCursor(m[1] - 1, m[2] ? m[2] - 1 : cur.ch);
}
}, {value: cur.line+1});
},
"Alt-PageDown": function(cm) {
editors[(editors.indexOf(cm) + 1) % editors.length].focus();
},
"Alt-PageUp": function(cm) {
editors[(editors.indexOf(cm) - 1 + editors.length) % editors.length].focus();
}
});
cm.lastChange = cm.changeGeneration();
cm.on("change", indicateCodeChange);
editors.push(cm);