Skip to content

Commit

Permalink
Fix bad display of wrapped whitespace in highlightWhitespace
Browse files Browse the repository at this point in the history
FIX: Fix an issue where the dots past the wrapping point were displayed incorrectly
when using `highlightWhitespace` with a wrapped sequence of spaces.

Closes codemirror/dev#1444
  • Loading branch information
marijnh committed Sep 23, 2024
1 parent 48ffb17 commit aea2395
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
22 changes: 5 additions & 17 deletions src/highlight-space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,6 @@ import {ViewPlugin} from "./extension"
import {MatchDecorator} from "./matchdecorator"
import {Decoration} from "./decoration"

const WhitespaceDeco = new Map<string, Decoration>()

function getWhitespaceDeco(space: string): Decoration {
let deco = WhitespaceDeco.get(space)
if (!deco) WhitespaceDeco.set(space, deco = Decoration.mark({
attributes: space === "\t" ? {
class: "cm-highlightTab",
} : {
class: "cm-highlightSpace",
"data-display": space.replace(/ /g, "·")
}
}))
return deco
}

function matcher(decorator: MatchDecorator): Extension {
return ViewPlugin.define(view => ({
decorations: decorator.createDeco(view),
Expand All @@ -29,9 +14,12 @@ function matcher(decorator: MatchDecorator): Extension {
})
}

const tabDeco = Decoration.mark({class: "cm-highlightTab"})
const spaceDeco = Decoration.mark({class: "cm-highlightSpace"})

const whitespaceHighlighter = matcher(new MatchDecorator({
regexp: /\t| +/g,
decoration: match => getWhitespaceDeco(match[0]),
regexp: /\t| /g,
decoration: match => match[0] == "\t" ? tabDeco : spaceDeco,
boundary: /\S/,
}))

Expand Down
2 changes: 1 addition & 1 deletion src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export const baseTheme = buildTheme("." + baseThemeID, {
},

".cm-highlightSpace:before": {
content: "attr(data-display)",
content: '"·"',
position: "absolute",
pointerEvents: "none",
color: "#888"
Expand Down

0 comments on commit aea2395

Please sign in to comment.