Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/read-only/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Trame setup
# -----------------------------------------------------------------------------

server = get_server()
server = get_server(client_type="vue2")
state, ctrl = server.state, server.controller


Expand Down
4 changes: 4 additions & 0 deletions trame_code/widgets/code.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Module compatible with vue2 and vue3. To use it, you need to install **trame-code**"""

from trame_client.widgets.core import AbstractElement

from .. import module

__all__ = [
Expand All @@ -23,6 +25,7 @@ class Editor(HtmlElement):

:param options:
:param value:
:param model_value:
:param theme:
:param language:
:param textmate:
Expand All @@ -41,6 +44,7 @@ def __init__(self, **kwargs):
self._attr_names += [
"options",
"value",
("model_value", "modelValue"),
"theme",
"language",
"textmate",
Expand Down
27 changes: 21 additions & 6 deletions vue-components/src/components/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import * as monaco from "monaco-editor";
export default {
name: "VSEditor",
props: {
modelValue: {
type: String,
},
value: {
type: String,
default: "",
},
options: {
type: Object,
Expand All @@ -34,8 +36,13 @@ export default {
},
},
watch: {
modelValue(v) {
if (this.editor && v !== undefined && this.editor.getValue() !== v) {
this.editor.setValue(v);
}
},
value(v) {
if (this.editor) {
if (this.editor && v !== undefined && this.editor.getValue() !== v) {
this.editor.setValue(v);
}
},
Expand Down Expand Up @@ -102,7 +109,7 @@ export default {
}

this.editor = monaco.editor.create(this.$el, {
value: this.value,
value: this.modelValue || this.value,
language: this.language,
theme: this.theme,
...this.options,
Expand All @@ -112,9 +119,17 @@ export default {
provider.injectCSS();
}

this.editor.onDidChangeModelContent(() =>
this.$emit("input", this.editor.getValue())
);
this.lastValue = this.editor.getValue();

this.editor.onDidChangeModelContent(() => {
const newValue = this.editor.getValue();
if (this.lastValue === newValue) {
return;
}
this.lastValue = newValue;
this.$emit("update:modelValue", newValue);
this.$emit("input", newValue);
});
},
beforeUnmount() {
this.editor.dispose();
Expand Down
Loading