From bdc75e1cea383a55e2d126b3f2e2a4f3513183d1 Mon Sep 17 00:00:00 2001 From: Scharel Clemens Date: Tue, 4 Dec 2018 15:49:29 +0100 Subject: [PATCH] Added auto prepend for ordered lists --- qml/pages/EditPage.qml | 16 ++++++++++++---- rpm/harbour-nextcloudnotes.changes | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/qml/pages/EditPage.qml b/qml/pages/EditPage.qml index 9c53f15..70850f7 100644 --- a/qml/pages/EditPage.qml +++ b/qml/pages/EditPage.qml @@ -53,16 +53,24 @@ Dialog { text: note.content font.family: appSettings.useMonoFont ? "DejaVu Sans Mono" : Theme.fontFamily // "Courier" property int preTextLength: 0 - property var listPrefixes: ["- ", "* ", "+ ", "- [ ] ", "- [x] ", "- [X] "] + property var listPrefixes: [/^- /gm, /^\* /gm, /^\+ /gm, /^- \[ \] /gm, /^- \[[xX]\] /gm, /^\d+. /gm] onTextChanged: { if (page.status === PageStatus.Active && text.length > preTextLength && text.charAt(cursorPosition-1) === "\n") { var clipboard = "" var preLine = text.substring(text.lastIndexOf("\n", cursorPosition-2), text.indexOf("\n", cursorPosition-1)) - listPrefixes.forEach(function(currentValue) { - if (preLine.indexOf(currentValue) === 1) - clipboard = currentValue + listPrefixes.forEach(function(currentValue, index) { + var prefix = preLine.match(currentValue) + if (prefix !== null) { + if (index === 5) { + var newListNumber = parseInt(prefix[0].split(". ")[0]) + 1 + clipboard = newListNumber.toString() + ". " + } + else { + clipboard = prefix[0] + } + } }) if (clipboard !== "") { var tmpClipboard = Clipboard.text diff --git a/rpm/harbour-nextcloudnotes.changes b/rpm/harbour-nextcloudnotes.changes index 908fad4..a887872 100644 --- a/rpm/harbour-nextcloudnotes.changes +++ b/rpm/harbour-nextcloudnotes.changes @@ -17,6 +17,7 @@ - Added: Option for monospaced font - Added: Option for capital X in checkboxes - Improved markdown parsing (espessialy lists, tables and images) +- Added auto prepend for ordered lists * Tue Dec 04 2018 Scharel Clemens 0.1-5 - Implemented auto prepend for list elements