From 599f4ccef421bc20298e4b2728d82c8d2e4d35c9 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Thu, 21 Jun 2018 18:53:42 +0100 Subject: [PATCH] Electron: Fixes #626: Auto-completion for indented items --- ElectronClient/app/gui/NoteText.jsx | 25 ++++++++++++++++++++----- README.md | 2 +- docs/index.html | 2 +- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/ElectronClient/app/gui/NoteText.jsx b/ElectronClient/app/gui/NoteText.jsx index 4e261488d4..164db90a2f 100644 --- a/ElectronClient/app/gui/NoteText.jsx +++ b/ElectronClient/app/gui/NoteText.jsx @@ -615,6 +615,18 @@ class NoteTextComponent extends React.Component { document.querySelector('#note-editor').addEventListener('paste', this.onEditorPaste_, true); document.querySelector('#note-editor').addEventListener('keydown', this.onEditorKeyDown_); + const lineLeftSpaces = function(line) { + let output = ''; + for (let i = 0; i < line.length; i++) { + if ([' ', '\t'].indexOf(line[i]) >= 0) { + output += line[i]; + } else { + break; + } + } + return output; + } + // Disable Markdown auto-completion (eg. auto-adding a dash after a line with a dash. // https://github.com/ajaxorg/ace/issues/2754 const that = this; // The "this" within the function below refers to something else @@ -622,12 +634,15 @@ class NoteTextComponent extends React.Component { const ls = that.state.lastKeys; if (ls.length >= 2 && ls[ls.length - 1] === 'Enter' && ls[ls.length - 2] === 'Enter') return this.$getIndent(line); - if (line.indexOf('- [ ] ') === 0 || line.indexOf('- [x] ') === 0 || line.indexOf('- [X] ') === 0) return '- [ ] '; - if (line.indexOf('- ') === 0) return '- '; - if (line.indexOf('* ') === 0) return '* '; + const leftSpaces = lineLeftSpaces(line); + const lineNoLeftSpaces = line.trimLeft(); - const bulletNumber = markdownUtils.olLineNumber(line); - if (bulletNumber) return (bulletNumber + 1) + '. '; + if (lineNoLeftSpaces.indexOf('- [ ] ') === 0 || lineNoLeftSpaces.indexOf('- [x] ') === 0 || lineNoLeftSpaces.indexOf('- [X] ') === 0) return leftSpaces + '- [ ] '; + if (lineNoLeftSpaces.indexOf('- ') === 0) return leftSpaces + '- '; + if (lineNoLeftSpaces.indexOf('* ') === 0) return leftSpaces + '* '; + + const bulletNumber = markdownUtils.olLineNumber(lineNoLeftSpaces); + if (bulletNumber) return leftSpaces + (bulletNumber + 1) + '. '; return this.$getIndent(line); }; diff --git a/README.md b/README.md index 5ab3e98a4e..a554cbb45c 100644 --- a/README.md +++ b/README.md @@ -280,7 +280,7 @@ Please see the [donation page](https://joplin.cozic.net/donate/) for information - For general discussion about Joplin, user support, software development questions, and to discuss new features, go to the [Joplin Forum](https://discourse.joplin.cozic.net/). It is possible to login with your GitHub account. - Also see here for information about [the latest releases and general news](https://discourse.joplin.cozic.net/c/news). - For bug reports and feature requests, go to the [GitHub Issue Tracker](https://github.com/laurent22/joplin/issues). -- The latest news are often posted [on this Twitter account](https://twitter.com/laurent2233). +- The latest news are posted [on the Patreon page](https://www.patreon.com/joplin). # Contributing diff --git a/docs/index.html b/docs/index.html index 083b7d0a0c..0ddccbcd16 100644 --- a/docs/index.html +++ b/docs/index.html @@ -474,7 +474,7 @@ $$
  • For general discussion about Joplin, user support, software development questions, and to discuss new features, go to the Joplin Forum. It is possible to login with your GitHub account.
  • Also see here for information about the latest releases and general news.
  • For bug reports and feature requests, go to the GitHub Issue Tracker.
  • -
  • The latest news are often posted on this Twitter account.
  • +
  • The latest news are posted on the Patreon page.
  • Contributing

    Please see the guide for information on how to contribute to the development of Joplin: https://github.com/laurent22/joplin/blob/master/CONTRIBUTING.md