Skip to content

Commit

Permalink
Version 0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
FIameCaster committed Aug 8, 2023
1 parent 08e05ad commit 6577c76
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prism-code-editor",
"version": "0.0.2",
"version": "0.0.3",
"type": "module",
"description": "Lightweight, extensible code editor for the web using Prism",
"main": "./dist/index.js",
Expand Down
4 changes: 2 additions & 2 deletions package/src/extensions/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ const clipboard = navigator.clipboard
* Defaults to `['""', "''", '``', '()', '[]', '{}']`.
* @param selfCloseRegex Regexp controlling whether or not a bracket/quote should
* automatically close based on the character before and after the cursor.
* Defaults to ``/([^\w$'"`]["'`]|.[[({])[,.\])}>\s]|.[[({]`/s``.
* Defaults to ``/([^\w$'"`]["'`]|.[[({])[;:,.\])}>\s]|.[[({]`/s``.
*/
export const defaultCommands = (
cursor?: Cursor,
selfClosePairs = ['""', "''", "``", "()", "[]", "{}"],
selfCloseRegex = /([^\w$'"`]["'`]|.[[({])[,.\])}>\s]|.[[({]`/s,
selfCloseRegex = /([^\w$'"`]["'`]|.[[({])[;:,.\])}>\s]|.[[({]`/s,
): Extension => {
let initialized: boolean, prevCopy: string

Expand Down
5 changes: 3 additions & 2 deletions package/src/extensions/matchBrackets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export const matchBrackets = (
let pairs: number[][] = [],
secondOrder: number[][],
activeID: number,
prevPair: number[],
currentEditor: PrismEditor,
openingBrackets: HTMLCollectionOf<HTMLSpanElement>,
closingBrackets: HTMLCollectionOf<HTMLSpanElement>
Expand All @@ -104,7 +103,7 @@ export const matchBrackets = (
selectionChange = () => {
const [start, end] = currentEditor.getSelection()
const newID = start == end && currentEditor.focused ? getClosest(start) : -1
if (prevPair != (prevPair = pairs[newID])) {
if (activeID != newID) {
toggleBrackets(activeID, false)
toggleBrackets((activeID = newID), true)
}
Expand All @@ -129,6 +128,8 @@ export const matchBrackets = (
addListener("selectionChange", selectionChange)
addListener("tokenize", (env: TokenizeEnv) => {
if (env.language != "regex") {
toggleBrackets(activeID, false)
activeID = -1
pairs = pairBrackets(env.tokens, openingRegex, closingRegex, pairRegex)
secondOrder = pairs.slice().sort((a, b) => a[0] - b[0])
}
Expand Down

0 comments on commit 6577c76

Please sign in to comment.