diff --git a/src/components/EditorBody.vue b/src/components/EditorBody.vue index 338b61f..5e9a8b8 100644 --- a/src/components/EditorBody.vue +++ b/src/components/EditorBody.vue @@ -8,10 +8,6 @@ @click="jumpGoto" :highlight="gotoHighlights.state.highlight" /> - @@ -27,7 +23,6 @@ import { } from '../state/state' import { isSyncing } from '../utils/tabs' import GotoOverlay from './GotoOverlay.vue' -import ErrorOverlay from './ErrorOverlay.vue' import { EditorView } from 'codemirror' import { darkTheme, editorTheme, lightTheme } from '../utils/lezer-mips' diff --git a/src/components/ErrorOverlay.vue b/src/components/ErrorOverlay.vue deleted file mode 100644 index da18adc..0000000 --- a/src/components/ErrorOverlay.vue +++ /dev/null @@ -1,29 +0,0 @@ - - - diff --git a/src/components/ExportModal.vue b/src/components/ExportModal.vue index f1c1885..f25ccf0 100644 --- a/src/components/ExportModal.vue +++ b/src/components/ExportModal.vue @@ -156,7 +156,7 @@ async function exportRegions() { return } - const result = await backend.assembleRegions(collectLines(current.lines), current.path, state) + const result = await backend.assembleRegions(current.doc, current.path, state) if (result.regions) { switch (result.regions.type) { diff --git a/src/components/console/ConsoleTab.vue b/src/components/console/ConsoleTab.vue index 617a10f..a5dbe6c 100644 --- a/src/components/console/ConsoleTab.vue +++ b/src/components/console/ConsoleTab.vue @@ -107,7 +107,7 @@ function makeEditor(): Editor { ) } - return new Editor(consoleData.console, cursor, () => {}, writable) + return new Editor(consoleData.console, cursor, writable) } const state = reactive({ diff --git a/src/state/state.ts b/src/state/state.ts index b0b578a..8e2211c 100644 --- a/src/state/state.ts +++ b/src/state/state.ts @@ -2,17 +2,13 @@ import { useSettings } from '../utils/settings' import { useHighlights } from '../utils/highlights' import { regular } from '../utils/query/text-size' import { useStorage } from '../utils/storage' - import { useTabs } from '../utils/tabs' import { GotoMessage, useGoto } from '../utils/goto' import { ref } from 'vue' +import { InstructionLine } from '../utils/mips/mips' export const settings = useSettings() -function widthQuery(text: string) { - return regular.calculate(text).width -} - export const { tabsState, tab, @@ -23,17 +19,14 @@ export const { showSettings } = useTabs() -export const errorHighlights = useHighlights(widthQuery) -export const gotoHighlights = useHighlights(widthQuery) +export const errorHighlights = useHighlights() +export const gotoHighlights = useHighlights() -const storageResult = useStorage(errorHighlights, tab, onDirty) +const storageResult = useStorage(errorHighlights, tab) export const { editor, storage, suggestionsStorage } = storageResult -function onDirty(line: number, deleted: number, insert: string[]) { - -} // watch(() => { // // const cursor = cursorIndex() // // const line = tab()?.lines[cursor.line] @@ -46,3 +39,5 @@ function onDirty(line: number, deleted: number, insert: string[]) { export const goto = useGoto(gotoHighlights, storageResult) export const showExportRegionsDialog = ref(false) + +export const buildLines = ref(null as InstructionLine[] | null) diff --git a/src/utils/editor.ts b/src/utils/editor.ts index d40d418..b08f790 100644 --- a/src/utils/editor.ts +++ b/src/utils/editor.ts @@ -178,8 +178,6 @@ export class Editor { body() this.redoOperations = [] - - this.onDirty(line, count, this.data.slice(line, line + insert)) } public mutateLine(line: number, body: () => void) { @@ -205,7 +203,6 @@ export class Editor { frame.replaced, ...frame.deleted ) - this.onDirty(frame.index, frame.replaced, frame.deleted) return { index: frame.index, @@ -516,7 +513,6 @@ export class Editor { constructor( public data: LineData, public cursor: SelectionIndex, - public onDirty: DirtyHandler = () => {}, public writable?: ( start: number, deleted: number, diff --git a/src/utils/events.ts b/src/utils/events.ts index 4dd3d9f..c8928fa 100644 --- a/src/utils/events.ts +++ b/src/utils/events.ts @@ -293,7 +293,7 @@ export async function setupEvents() { if (current?.uuid === tab.uuid) { editor.value.replaceAll(modification.data) } else { - tab.lines = splitLines(modification.data) + tab.doc = modification.data } tab.marked = false diff --git a/src/utils/goto.ts b/src/utils/goto.ts index 97da9ac..8f7ba75 100644 --- a/src/utils/goto.ts +++ b/src/utils/goto.ts @@ -17,7 +17,6 @@ export interface GotoMessage { export interface GotoInterface { dismiss(): void - hover(line: number, index: number): void jump(): SelectionIndex | null } @@ -59,50 +58,6 @@ export function useGoto( highlights.dismissHighlight() } - function hover(line: number, index: number) { - highlights.dismissHighlight() - - const tokens = storage.storage.highlights[line] - const tokenIndex = findTokenIndex(tokens, index) - - if (tokenIndex === null) { - return - } - - let match: SearchStorageResult | null - - if (cache && cache.line === line && cache.index === tokenIndex) { - match = cache.match - } else { - const token = tokens[tokenIndex] - const text = token.text.trim() - - const suggestions = storage.suggestionsStorage() - // I don't care about the performance of this feature too much - match = searchStorage(text, suggestions.body) - - cache = { - line: line, - index: tokenIndex, - token, - match, - } - } - - if (!match) { - return - } - - const message: GotoMessage = { - label: match.suggestion.replace, - line: match.line, - index: match.suggestion.index, - type: match.suggestion.type, - } - - highlights.putHighlight(line, tokenIndex, tokens, message) - } - function jump(): SelectionIndex | null { highlights.dismissHighlight() @@ -119,7 +74,6 @@ export function useGoto( return { dismiss, - hover, jump, } } diff --git a/src/utils/highlights.ts b/src/utils/highlights.ts index 8037960..f2de704 100644 --- a/src/utils/highlights.ts +++ b/src/utils/highlights.ts @@ -5,6 +5,7 @@ type DefaultMessage = string export interface Highlights { line: number offset: number + size: number message: Message } @@ -35,7 +36,7 @@ export function useHighlights(): HighlightsResult ) { - state.highlight = { line, message, offset: index } + state.highlight = { line, message, offset: index, size: 0 } } function dismissHighlight() { diff --git a/src/utils/storage.ts b/src/utils/storage.ts index a82ad2f..dc35352 100644 --- a/src/utils/storage.ts +++ b/src/utils/storage.ts @@ -27,7 +27,6 @@ type ShiftCallback = (line: number, deleted: number, insert: string[]) => void export function useStorage( error: HighlightsInterface, tab: () => EditorTab | null, - dirty: ShiftCallback = () => {} ): StorageResult { const storage = reactive({ editor: createEditor(), @@ -38,17 +37,6 @@ export function useStorage( // Not reactive. let suggestions = new SuggestionsStorage() - function highlight(line: number, deleted: number, lines: string[]) { - const result = lines.map((part) => storage.language.highlight(part)) - - storage.highlights.splice(line, deleted, ...result.map((x) => x.tokens)) - suggestions.update( - line, - deleted, - result.map((x) => x.suggestions) - ) - } - async function checkSyntax() { const current = tab() @@ -77,59 +65,12 @@ export function useStorage( } } - function shiftBreakpoints(line: number, deleted: number, replaced: number) { - const current = tab() - - if (!current) { - return - } - - const breakpoints = current.breakpoints - - let moved = false - - for (let a = 0; a < breakpoints.length; a++) { - const bp = breakpoints[a] - - if (bp < line + Math.min(deleted, replaced)) { - } else if (deleted > replaced && bp < line + deleted) { - breakpoints.splice(a, 1) - a -= 1 - } else { - breakpoints[a] += replaced - deleted - moved = true - } - } - - if (moved) { - current.breakpoints = [...new Set(current.breakpoints)] - } - } - - function handleDirty(line: number, deleted: number, lines: string[]) { - highlight(line, deleted, lines) - - const current = tab() - - if (current) { - current.marked = true - } - - error.shiftHighlight(line, deleted, lines.length) - shiftBreakpoints(line, deleted, lines.length) - - dirty(line, deleted, lines) - - dispatchCheckSyntax() - } - function createEditor(): Editor { const current = tab() return new Editor( current?.state.doc.toString().split("\n") ?? ['Nothing yet.'], { line: 0, index: 0 }, - handleDirty, current?.writable ?? false ? undefined : () => false // weird ) }