mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-10 15:42:39 +00:00
Merge pull request #2392 from G-Ambatte/stopUnfoldingCode-#2135
[Editor] Prevent unfolding code in Editor when adding a Snippet
This commit is contained in:
@@ -19,11 +19,6 @@ const DEFAULT_STYLE_TEXT = dedent`
|
|||||||
color: black;
|
color: black;
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
const splice = function(str, index, inject){
|
|
||||||
return str.slice(0, index) + inject + str.slice(index);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const Editor = createClass({
|
const Editor = createClass({
|
||||||
displayName : 'Editor',
|
displayName : 'Editor',
|
||||||
@@ -80,19 +75,7 @@ const Editor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
handleInject : function(injectText){
|
handleInject : function(injectText){
|
||||||
let text;
|
this.refs.codeEditor?.injectText(injectText, false);
|
||||||
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,15 @@ const CodeEditor = createClass({
|
|||||||
this.codeMirror.replaceSelection('\n\\page\n\n', 'end');
|
this.codeMirror.replaceSelection('\n\\page\n\n', 'end');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
injectText : function(injectText, overwrite=true) {
|
||||||
|
const cm = this.codeMirror;
|
||||||
|
if(!overwrite) {
|
||||||
|
cm.setCursor(cm.getCursor('from'));
|
||||||
|
}
|
||||||
|
cm.replaceSelection(injectText, 'end');
|
||||||
|
cm.focus();
|
||||||
|
},
|
||||||
|
|
||||||
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