Skip to content

Commit

Permalink
feat(): highlight pebble in monaco
Browse files Browse the repository at this point in the history
  • Loading branch information
Skraye committed Mar 26, 2024
1 parent f564a46 commit b84ebfb
Showing 1 changed file with 47 additions and 4 deletions.
51 changes: 47 additions & 4 deletions ui/src/components/inputs/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@
<slot name="nav">
<div class="text-nowrap">
<el-button-group>
<el-tooltip :content="$t('Fold content lines')" :persistent="false" transition="" :hide-after="0">
<el-tooltip
:content="$t('Fold content lines')"
:persistent="false"
transition=""
:hide-after="0"
>
<el-button :icon="icon.UnfoldLessHorizontal" @click="autoFold(true)" size="small" />
</el-tooltip>
<el-tooltip :content="$t('Unfold content lines')" :persistent="false" transition="" :hide-after="0">
<el-tooltip
:content="$t('Unfold content lines')"
:persistent="false"
transition=""
:hide-after="0"
>
<el-button :icon="icon.UnfoldMoreHorizontal" @click="unfoldAll" size="small" />
</el-tooltip>
</el-button-group>
Expand Down Expand Up @@ -178,7 +188,7 @@
return {
...{
tabSize: 2,
fontFamily: localStorage.getItem("editorFontFamily") ? localStorage.getItem("editorFontFamily") : "'Source Code Pro', monospace",
fontFamily: localStorage.getItem("editorFontFamily") ? localStorage.getItem("editorFontFamily") : "'Source Code Pro', monospace",
fontSize: localStorage.getItem("editorFontSize") ? parseInt(localStorage.getItem("editorFontSize")) : 12,
showFoldingControls: "always",
scrollBeyondLastLine: false,
Expand Down Expand Up @@ -320,7 +330,7 @@
]) : decorations;
this.oldDecorations = this.editor.deltaDecorations(this.oldDecorations, decorations)
} else {
this.oldDecorations = this.editor.deltaDecorations(this.oldDecorations, []);
this.highlightPebble();
}
});
Expand All @@ -331,6 +341,7 @@
this.lastTimeout = setTimeout(() => {
this.$emit("cursor", {position: position, model: model})
}, 100);
this.highlightPebble();
});
}
},
Expand All @@ -349,6 +360,30 @@
this.editor.layout()
this.editor.focus()
},
highlightPebble() {
// Highlight code that match pebble content
let model = this.editor.getModel();
let decorations = [];
let text = model.getValue();
let regex = new RegExp("\\{\\{(.+?)}}", "g");
let match;
while ((match = regex.exec(text)) !== null) {
let startPos = model.getPositionAt(match.index);
let endPos = model.getPositionAt(match.index + match[0].length);
decorations.push({
range: {
startLineNumber: startPos.lineNumber,
startColumn: startPos.column,
endLineNumber: endPos.lineNumber,
endColumn: endPos.column
},
options: {
inlineClassName: "highlight-pebble"
}
});
}
this.oldDecorations = this.editor.deltaDecorations(this.oldDecorations, decorations);
}
},
};
</script>
Expand Down Expand Up @@ -463,6 +498,14 @@
}
}
.highlight-pebble {
color: #977100 !important;
html.dark & {
color: #ffca16 !important;
}
}
.disable-text {
color: grey !important;
}
Expand Down

0 comments on commit b84ebfb

Please sign in to comment.