File tree Expand file tree Collapse file tree 3 files changed +4
-31
lines changed
Expand file tree Collapse file tree 3 files changed +4
-31
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
2424 This reduces code duplication and makes it easier to add
2525 new languages in the future.
2626- Flat switches now generate nodes for the conditions, and not only the consequence.
27+ - The CodeMirror editor in the demo got it's own Svelte component now, ` Editor.svelte ` .
28+ This allows better state management and handling/dispatching events.
2729
2830## [ 0.0.5] - 2024-09-18
2931
Original file line number Diff line number Diff line change 9292 downloadString (svg , " image/svg+xml" , " function-graph-overview.svg" );
9393 }
9494
95- function gotoLine(event ) {
96- if (! editor ) return ;
97- editor .goto (event .detail .lineNumber );
98- }
99- let editor: Editor ;
100-
10195 function cursorMoved(event ): void {
10296 const { index } = event .detail .pos ;
10397 offsetToHighlight = index ;
128122 </div >
129123 <div class =" codemirror" >
130124 {#if selection .language === " Go" }
131- <Editor
132- bind:code ={codeGo }
133- lang ={go ()}
134- bind:this ={editor }
135- on:cursorMoved ={cursorMoved }
136- />
125+ <Editor bind:code ={codeGo } lang ={go ()} on:cursorMoved ={cursorMoved } />
137126 {:else if selection .language === " C" }
138- <Editor
139- bind:code ={codeC }
140- lang ={cpp ()}
141- bind:this ={editor }
142- on:cursorMoved ={cursorMoved }
143- />
127+ <Editor bind:code ={codeC } lang ={cpp ()} on:cursorMoved ={cursorMoved } />
144128 {:else if selection .language === " Python" }
145129 <Editor
146130 bind:code ={codePython }
147131 lang ={python ()}
148- bind:this ={editor }
149132 on:cursorMoved ={cursorMoved }
150133 />
151134 {/if }
178161 {flatSwitch }
179162 {verbose }
180163 bind:this ={graph }
181- on:goto ={gotoLine }
182164 />
183165 </div >
184166</main >
Original file line number Diff line number Diff line change 11<script lang =" ts" >
22 import type { LanguageSupport } from " @codemirror/language" ;
3- import { EditorSelection } from " @codemirror/state" ;
43 import type { EditorView } from " @codemirror/view" ;
54 import { createEventDispatcher } from " svelte" ;
65 import CodeMirror from " svelte-codemirror-editor" ;
1211
1312 const dispatch = createEventDispatcher ();
1413
15- export function goto(row : number , column : number = 0 ) {
16- if (! editorView ) return ;
17- const pos = editorView .state .doc .line (row + 1 ).from + column ;
18- editorView .dispatch ({
19- selection: EditorSelection .create ([EditorSelection .cursor (pos )]),
20- });
21- // TODO: actually enable this, once we fix the node mapping.
22- // updateCursorPosition();
23- }
24-
2514 function updateCursorPosition() {
2615 const pos = editorView .state .selection .main .head ;
2716 let { number, from, to } = editorView .state .doc .lineAt (pos );
You can’t perform that action at this time.
0 commit comments