mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-08 07:32:40 +00:00
Use cm.replaceSelection instead of split/join text
This commit is contained in:
@@ -80,19 +80,7 @@ const Editor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
handleInject : function(injectText){
|
handleInject : function(injectText){
|
||||||
let text;
|
this.refs.codeEditor?.injectText(injectText);
|
||||||
if(this.isText()) text = this.props.brew.text;
|
|
||||||
if(this.isStyle()) text = this.props.brew.style ?? DEFAULT_STYLE_TEXT;
|
|
||||||
|
|
||||||
const lines = text.split('\n');
|
|
||||||
const cursorPos = this.refs.codeEditor.getCursorPosition();
|
|
||||||
lines[cursorPos.line] = splice(lines[cursorPos.line], cursorPos.ch, injectText);
|
|
||||||
|
|
||||||
const injectLines = injectText.split('\n');
|
|
||||||
this.refs.codeEditor.setCursorPosition(cursorPos.line + injectLines.length, cursorPos.ch + injectLines[injectLines.length - 1].length);
|
|
||||||
|
|
||||||
if(this.isText()) this.props.onTextChange(lines.join('\n'));
|
|
||||||
if(this.isStyle()) this.props.onStyleChange(lines.join('\n'));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
handleViewChange : function(newView){
|
handleViewChange : function(newView){
|
||||||
|
|||||||
@@ -229,6 +229,10 @@ const CodeEditor = createClass({
|
|||||||
this.codeMirror.replaceSelection('\n\\page\n\n', 'end');
|
this.codeMirror.replaceSelection('\n\\page\n\n', 'end');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
injectText : function(injectText) {
|
||||||
|
this.codeMirror.replaceSelection(injectText, 'around');
|
||||||
|
},
|
||||||
|
|
||||||
makeUnderline : function() {
|
makeUnderline : function() {
|
||||||
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 3) === '<u>' && selection.slice(-4) === '</u>';
|
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 3) === '<u>' && selection.slice(-4) === '</u>';
|
||||||
this.codeMirror.replaceSelection(t ? selection.slice(3, -4) : `<u>${selection}</u>`, 'around');
|
this.codeMirror.replaceSelection(t ? selection.slice(3, -4) : `<u>${selection}</u>`, 'around');
|
||||||
|
|||||||
Reference in New Issue
Block a user