Skip to content

Commit

Permalink
highlight working
Browse files Browse the repository at this point in the history
  • Loading branch information
edublancas authored and brichet committed Dec 27, 2023
1 parent fc42fec commit aed4e9c
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,46 @@ const showStripes = ViewPlugin.fromClass(
) {
this.decorations = stripeDeco(update.view);
}


// let docIsSQL = /^\s*SELECT/.test(update.state.doc.sliceString(0, 100))
// // let stateIsSQL = tr.startState.facet(language) == htmlLanguage
// // if (docIsSQL == stateIsSQL) return null
// update.view.dispatch({
// effects: languageConf.reconfigure(docIsSQL ? sql() : sql())
// })
}
},
{
decorations: v => v.decorations
}
);


import { EditorState, Compartment } from "@codemirror/state"
// import { language } from "@codemirror/language"
import { python } from "@codemirror/lang-python"

const languageConf = new Compartment

const autoLanguage = EditorState.transactionExtender.of(tr => {
// if (!tr.docChanged) return null
let docIsSQL = /^\s*%{1,2}sql/.test(tr.newDoc.sliceString(0, 100))
// let stateIsSQL = tr.startState.facet(language) == htmlLanguage
// if (docIsSQL == stateIsSQL) return null
return {
effects: languageConf.reconfigure(docIsSQL ? sql() : python())
}
})


// Full extension composed of elemental extensions
export function zebraStripes(options: { step?: number } = {}): Extension {
return [
baseTheme,
typeof options.step !== 'number' ? [] : stepSize.of(options.step),
showStripes,
sql()
languageConf.of(python()),
autoLanguage,
];
}

0 comments on commit aed4e9c

Please sign in to comment.