Skip to content

Commit

Permalink
#10 capture gutter event
Browse files Browse the repository at this point in the history
  • Loading branch information
Blankll committed Aug 13, 2023
1 parent 51fc7a5 commit 77caca2
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions src/views/editor/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,6 @@ watch(
},
);
const decorations = [
{
range: new monaco.Range(2, 1, 2, 1),
options: {
isWholeLine: true,
linesDecorationsClassName: 'execute-button-decoration',
},
},
];
const code = `// Type source code in your language here...
GET students/_search
{
Expand All @@ -349,42 +340,60 @@ GET students/_search
}
}
`;
const executionClass = 'action-execute-decoration';
const executionGutterClass = 'execute-button-decoration';
const executeDecorations = [];

Check failure on line 345 in src/views/editor/index.vue

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18.x)

Variable 'executeDecorations' implicitly has type 'any[]' in some locations where its type cannot be determined.

Check failure on line 345 in src/views/editor/index.vue

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

Variable 'executeDecorations' implicitly has type 'any[]' in some locations where its type cannot be determined.

Check failure on line 345 in src/views/editor/index.vue

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18.x)

Variable 'executeDecorations' implicitly has type 'any[]' in some locations where its type cannot be determined.
const refreshActionMarks = (editor: monaco.Editor) => {

Check failure on line 346 in src/views/editor/index.vue

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18.x)

'"/Users/runner/work/dockit/dockit/node_modules/monaco-editor/esm/vs/editor/editor.api"' has no exported member named 'Editor'. Did you mean 'editor'?

Check failure on line 346 in src/views/editor/index.vue

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

'"/home/runner/work/dockit/dockit/node_modules/monaco-editor/esm/vs/editor/editor.api"' has no exported member named 'Editor'. Did you mean 'editor'?

Check failure on line 346 in src/views/editor/index.vue

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18.x)

'"D:/a/dockit/dockit/node_modules/monaco-editor/esm/vs/editor/editor.api"' has no exported member named 'Editor'. Did you mean 'editor'?
// Get the model of the editor
const model = editor.getModel();
// Tokenize the entire content of the model
const tokens = monaco.editor.tokenize(model!.getValue(), model!.getLanguageId());
tokens.forEach((lineTokens, lineNumber) => {
tokens.forEach((lineTokens, lineIndex) => {
lineTokens.forEach(token => {
if (token.type === 'action-execute-decoration.search') {
const lineContent = model.getLineContent(lineNumber + 1);
const range = new monaco.Range(lineNumber + 1, 0, lineNumber + 1, lineContent.length);
// eslint-disable-next-line no-console
console.log({ range, lineNumber, lineTokens, lineContent });
editor.deltaDecorations(
[],
[{ range, options: { className: executionClass, isWholeLine: true } }],
);
const lineNumber = lineIndex + 1;
const decoration = {
id: `${lineNumber}-1${lineNumber}-1`,
range: new monaco.Range(lineNumber, 1, lineNumber, 1),
options: {
isWholeLine: true,
linesDecorationsClassName: executionGutterClass,
},
};
executeDecorations.push(decoration);
editor.deltaDecorations([], executeDecorations);

Check failure on line 365 in src/views/editor/index.vue

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18.x)

Variable 'executeDecorations' implicitly has an 'any[]' type.

Check failure on line 365 in src/views/editor/index.vue

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

Variable 'executeDecorations' implicitly has an 'any[]' type.

Check failure on line 365 in src/views/editor/index.vue

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18.x)

Variable 'executeDecorations' implicitly has an 'any[]' type.
}
});
});
};
const executeQueryAction = (
editor: monaco.Editor,

Check failure on line 371 in src/views/editor/index.vue

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18.x)

'"/Users/runner/work/dockit/dockit/node_modules/monaco-editor/esm/vs/editor/editor.api"' has no exported member named 'Editor'. Did you mean 'editor'?

Check failure on line 371 in src/views/editor/index.vue

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

'"/home/runner/work/dockit/dockit/node_modules/monaco-editor/esm/vs/editor/editor.api"' has no exported member named 'Editor'. Did you mean 'editor'?

Check failure on line 371 in src/views/editor/index.vue

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18.x)

'"D:/a/dockit/dockit/node_modules/monaco-editor/esm/vs/editor/editor.api"' has no exported member named 'Editor'. Did you mean 'editor'?
position: { column: number; lineNumber: number },
) => {
const model = editor.getModel();
const lineContent = model.getLineContent(position.lineNumber);
// eslint-disable-next-line no-console
console.log(`executeQueryAction ${lineContent}`);
};
onMounted(() => {
const editor = monaco.editor.create(editorRef.value, {
automaticLayout: true,
theme: editorTheme.value,
value: code,
language: 'search',
});
editor.createDecorationsCollection(decorations);
editorView.value = editor;
editor.onMouseDown(e => {
refreshActionMarks(editor);
// eslint-disable-next-line no-console
console.log('mousedown - ' + JSON.stringify(e));
if (
e.event.leftButton &&
e.target.type === 4 &&
Object.values(e.target!.element!.classList).includes(executionGutterClass)
) {
executeQueryAction(editor, e.target.position);
}
});
});
</script>
Expand All @@ -400,10 +409,4 @@ onMounted(() => {
width: 15px !important;
margin-left: 3px;
}
.action-execute-decoration {
background: blue;
cursor: pointer;
width: 15px !important;
margin-left: 3px;
}
</style>

0 comments on commit 77caca2

Please sign in to comment.