-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathindent-line.qml
39 lines (31 loc) · 1.23 KB
/
indent-line.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import QtQml 2.2
import QOwnNotesTypes 1.0
/// Toolbar buttons and context menu items to indent and unindent a text line.
Script {
property int indent_spaces_number
property var unindent_regex: new RegExp("^ {0," + indent_spaces_number + "}")
property variant settingsVariables: [
{
"identifier": "indent_spaces_number",
"name": "Number of spaces to indent/unindent a text line",
"type": "integer",
"default": 4,
},
]
function init() {
script.registerCustomAction("indent", "Indent current line", ">")
script.registerCustomAction("unindent", "Unindent current line", "<")
}
function customActionInvoked(action) {
if (action == "indent" || action == "unindent") {
const indent_spaces = " ".repeat(indent_spaces_number)
script.noteTextEditSelectCurrentLine()
var text_line = script.noteTextEditSelectedText()
if (action == "indent")
text_line = indent_spaces.concat(text_line)
else
text_line = text_line.replace(unindent_regex, "")
script.noteTextEditWrite(text_line)
}
}
}