Skip to content

Commit 79edf2d

Browse files
committed
improve completion provider and preview rendering
1 parent a504db1 commit 79edf2d

File tree

5 files changed

+805
-90
lines changed

5 files changed

+805
-90
lines changed

.changeset/beige-walls-remember.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"hyperbook-studio": minor
3+
---
4+
5+
Improve completion providers and preview rendering

platforms/vscode/snipptes/hyperbook.code-snippets

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,101 @@
173173
"body": [
174174
":::multievent",
175175
"",
176+
"$TM_SELECTED_TEXT$0",
176177
"",
177178
":::"
178179
]
179180
},
181+
"Element ABC Music": {
182+
"prefix": [":abc", ":abcjs"],
183+
"body": [
184+
"```abcjs",
185+
"X: 1",
186+
"T: ${1:Title}",
187+
"M: 4/4",
188+
"L: 1/8",
189+
"K: ${2:Emin}",
190+
"$TM_SELECTED_TEXT$0",
191+
"```"
192+
]
193+
},
194+
"Element ABC Music Editor": {
195+
"prefix": [":abc-editor", ":abcjs-editor"],
196+
"body": [
197+
"```abcjs editor",
198+
"X: 1",
199+
"T: ${1:Title}",
200+
"M: 4/4",
201+
"L: 1/8",
202+
"K: ${2:Emin}",
203+
"$TM_SELECTED_TEXT$0",
204+
"```"
205+
]
206+
},
207+
"Element GeoGebra": {
208+
"prefix": [":geogebra"],
209+
"body": [
210+
":::geogebra{perspective=\"${1:G}\" height=${2:400} width=${3:700}}",
211+
"",
212+
"$TM_SELECTED_TEXT$0",
213+
"",
214+
":::"
215+
]
216+
},
217+
"Element GeoGebra Inline": {
218+
"prefix": [":geogebra-inline"],
219+
"body": [
220+
"::geogebra{src=\"${1:https://www.geogebra.org/m/}\"}"
221+
]
222+
},
223+
"Element JSXGraph": {
224+
"prefix": [":jsxgraph"],
225+
"body": [
226+
":::jsxgraph{height=\"${1:500}\" width=\"${2:600}\" boundingbox=\"${3:[-10,10,10,-10]}\"}",
227+
"",
228+
"```js",
229+
"$TM_SELECTED_TEXT$0",
230+
"```",
231+
"",
232+
":::"
233+
]
234+
},
235+
"Element Learningmap": {
236+
"prefix": [":learningmap"],
237+
"body": [
238+
"::learningmap{id=\"${1:$RANDOM}\" height=\"${2:600px}\" src=\"${3:map.learningmap}\"}"
239+
]
240+
},
241+
"Element Textinput": {
242+
"prefix": [":textinput"],
243+
"body": [
244+
"::textinput{placeholder=\"${1:Enter text here}\" height=\"${2:200px}\" id=\"${3:$RANDOM}\"}"
245+
]
246+
},
247+
"Element Webide": {
248+
"prefix": [":webide"],
249+
"body": [
250+
":::webide{height=${1:500}}",
251+
"",
252+
"$TM_SELECTED_TEXT$0",
253+
"",
254+
":::"
255+
]
256+
},
257+
"Element Snippet": {
258+
"prefix": [":snippet", ":Snippet"],
259+
"body": [
260+
":::Snippet{#${1:snippet-name}}",
261+
"",
262+
"$TM_SELECTED_TEXT$0",
263+
"",
264+
":::"
265+
]
266+
},
267+
"Element Snippet Inline": {
268+
"prefix": [":snippet-inline"],
269+
"body": [
270+
":Snippet{#${1:snippet-name}}"
271+
]
272+
}
180273
}

platforms/vscode/src/Preview.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ export default class Preview {
306306
this.panel = vscode.window.createWebviewPanel(
307307
"liveHTMLPreview",
308308
"[Preview]" + fileName,
309-
viewColumn,
309+
{ viewColumn, preserveFocus: false },
310310
{
311311
enableScripts: true,
312312
retainContextWhenHidden: true,
@@ -326,12 +326,33 @@ export default class Preview {
326326

327327
vscode.workspace.onDidChangeConfiguration(
328328
this.handleTextDocumentChange.bind(this),
329+
null,
330+
this.disposables,
331+
);
332+
333+
const fileWatcher = vscode.workspace.createFileSystemWatcher("**/*");
334+
fileWatcher.onDidChange(
335+
async (uri) => {
336+
if (this._resource && this.panel) {
337+
const hyperbookRoot = await hyperbook.findRoot(this._resource.fsPath).catch(() => "");
338+
if (hyperbookRoot && uri.fsPath.startsWith(hyperbookRoot)) {
339+
await this.handleTextDocumentChange();
340+
}
341+
}
342+
},
343+
null,
344+
this.disposables,
329345
);
346+
330347
vscode.workspace.onDidSaveTextDocument(
331348
this.handleTextDocumentChange.bind(this),
349+
null,
350+
this.disposables,
332351
);
333352
vscode.window.onDidChangeActiveTextEditor(
334353
this.handleTextDocumentChange.bind(this),
354+
null,
355+
this.disposables,
335356
);
336357

337358
this.panel.onDidDispose(

0 commit comments

Comments
 (0)