Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
removeInlineStyle(): fix selection if it contains formatting characte…
Browse files Browse the repository at this point in the history
…rs (closes #166)
  • Loading branch information
brrd committed Oct 7, 2017
1 parent 54adaf8 commit 629d02d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/renderer/cm-extend-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ module.exports = function (CodeMirror) {
const removeInlineStyle = (style) => {
if (!style.reversible || style.delimiter == null) return;

// Fix selection if it contains formatting characters
const fixSelection = () => {
const delimiter = style.delimiter;
const length = delimiter.length;
const text = this.getSelection("\n");
if (text.length < length);
const cursorFrom = this.getCursor("from");
const cursorTo = this.getCursor("to");
if (text.slice(0, length) === delimiter) {
cursorFrom.ch += length;
}
if (text.slice(0 - length) === delimiter) {
cursorTo.ch -= length;
}
};

const getDelimiter = (pos, classname, step) => {
const getNextMove = (pos, step) => {
const lineLength = this.getLine(pos.line).length;
Expand Down Expand Up @@ -72,6 +88,8 @@ module.exports = function (CodeMirror) {
}
};

fixSelection();

const cursorFrom = this.getCursor("from");
const cursorTo = this.getCursor("to");
const delimiterClassname = getClassname(style, true);
Expand Down

0 comments on commit 629d02d

Please sign in to comment.