# Selection bug?

**URL:** <https://discuss.codemirror.net/t/selection-bug/9145>\
**Category:** v6\
**Created:** [April 19, 2025, 9:30pm UTC](https://discuss.codemirror.net/t/selection-bug/9145 "2025-04-19T21:30:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![feraxhp](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/feraxhp/32/4963_2.png) [@feraxhp](https://discuss.codemirror.net/u/feraxhp)\
**Post date:** [April 19, 2025, 9:30pm UTC](https://discuss.codemirror.net/t/selection-bug/9145/1 "2025-04-19T21:30:37Z")

</div>

I am trying to achieve that the text, when wrapped it, maintains the indentation, but, when i try to select the text this happens. someone know how to solve this issue?

 ![image](https://discuss.codemirror.net/uploads/default/original/2X/d/d05c054fff7384d2e7d443550d796d4cd816b2c3.png)

> the selection goes from “r” of “risks”. and ends in **left of `[!TIP]`**

Note that the text _“critical … risk”_ is at the same `cm-line`.

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [April 22, 2025, 11:59am UTC](https://discuss.codemirror.net/t/selection-bug/9145/2 "2025-04-22T11:59:49Z")

</div>

Are you doing anything odd with those widgets? Like making them float or absolutely positioning them?

---

<div class="post-metadata">

**Author:** ![feraxhp](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/feraxhp/32/4963_2.png) [@feraxhp](https://discuss.codemirror.net/u/feraxhp)\
**Post date:** [May 4, 2025, 8:15pm UTC](https://discuss.codemirror.net/t/selection-bug/9145/3 "2025-05-04T20:15:23Z")

</div>

This is all the css for that element

lineHeight: “1lh”,  
display: “inline-block”,  
paddingLeft: “6px”,  
textIndent: “-7px”,  
ariaHidden: “true”

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [May 5, 2025, 6:09am UTC](https://discuss.codemirror.net/t/selection-bug/9145/4 "2025-05-05T06:09:50Z")

</div>

Can you condense this down to a minimal example that can be run on [codemirror.net/try](https://codemirror.net/try)?

---

<div class="post-metadata">

**Author:** ![feraxhp](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/feraxhp/32/4963_2.png) [@feraxhp](https://discuss.codemirror.net/u/feraxhp)\
**Post date:** [May 5, 2025, 1:56pm UTC](https://discuss.codemirror.net/t/selection-bug/9145/5 "2025-05-05T13:56:03Z")

</div>

Yes, i already did it, i try my best to replicated

```javascript
import {minimalSetup , EditorView} from "codemirror"
import {markdown} from "@codemirror/lang-markdown"
import {languages} from "@codemirror/language-data"
import {ViewPlugin} from "@codemirror/view";
import { Decoration } from "@codemirror/view";
import { syntaxTree } from "@codemirror/language";

export const visibleNodes = ( view, iterator ) => {
    for (const { from, to } of view.visibleRanges) 
        syntaxTree(view.state).iterate({ ...iterator, from, to });
}

export function decorator(view, _) {
    const iterable = ["Document", "ListItem", "BulletList", "OrderedList"]

    const types = { Blockquote: () => { } }
    
    const marks = {
        QuoteMark: (from, to, type) => {
            const class_ = ["qt-mk"];
            if (type in quoteTypes) class_.push(quoteTypes[type]);
            else class_.push(quoteTypes["none"]);
            
            return Decoration.mark({
                class: class_.join(" ")
            }).range(from, to)
        },
        BlockquoteLine: (from, selected) => Decoration.line({ class: "bq-line " + (selected ? "sw": "") }).range(from),
        quoteLine: (from, to, offset) => {
            const width = `calc(100% - ${Math.max(0, offset) + 1.2}ch)`;
            return Decoration.mark({
                class: "bq-text-line",
                attributes: { style: `width: ${width}` }
            }).range(from, to)
        }
    }
    
    const getDecorations = (view, node, startLine, lines) => {
        const decorations = [];
        const { from, to } = node;
        const begin = startLine.number;
        
        const iterator = (start, end) => {
            let marksCount = 0;
            const stack = [];
            let marksEnd = 0;
            
            return {
                enter({ name, node, from, to }) {
                    if (name === "Blockquote") stack.push("none");
                    if (name === "QuoteMark") {
                        marksEnd = to;
                        marksCount++;
                    }
                },
                leave({ name, from, to }) {
                    if (name === "Paragraph") {
                        if (marksEnd < end) {
                            decorations.push(marks.quoteLine(marksEnd, end, marksEnd - start));
                        }
                    }
                }
            }
        }
        
        for ( let index = begin; index < lines + begin; index++) {
            const { from, to } = view.state.doc.line(index);
            decorations.push(marks.BlockquoteLine(from, true));
            
            syntaxTree(view.state).iterate({ from, to, ... iterator(from, to) })
        }
        
        
        return decorations
    }

    const widgets = [];
    
    visibleNodes(view, { 
        enter: ({ name }) => !(name in iterable),
        leave: ({ name, from, to, node}) => { 
            if (name !== "Blockquote") return;
            console.log("hola")
            const lines = view.state.sliceDoc(from, to).split("\n");
            const startLine = view.state.doc.lineAt(from);
            
            widgets.push(... getDecorations(view, node, startLine, lines.length))
        },
    });
    
    return Decoration.set(widgets, true)
}

export const PluginFactory = (func, conf, pluginSpec = {}) => {
    const decorator = class Decorator {
        decorations;
        conf;

        constructor(view) {
            this.conf = conf;
            this.decorations = func(view, this.conf);
        }

        update(update) {
            if (
                update.docChanged ||
                update.viewportChanged ||
                update.selectionSet
            ) this.decorations = func(update.view, this.conf);
        }
    }

    return ViewPlugin.fromClass(decorator, { decorations: (v) => v.decorations, ...pluginSpec })
}

export const coreTheme = () => {
    const width = "4px";
    return EditorView.baseTheme({
        "& .bq-text-line": { 
            lineHeight: "1lh",
            display: "inline-block",
            paddingLeft: "6px",
            textIndent: "-7px",
            ariaHidden: "true"
        },
    })
}
let view = new EditorView({
  doc: "some lines before\n> This is an example were the lime wraps, for that it need so much text, and more, and more and more.",
  extensions: [
    minimalSetup,
    EditorView.lineWrapping,
    PluginFactory(decorator, {}),
    coreTheme(),
    markdown({codeLanguages: languages})
  ],
  parent: document.body
})

```

and it works exactly like the other:

![image](https://discuss.codemirror.net/uploads/default/original/2X/e/e0cae665932bd703fd23486464513275dc3a862f.png).

> **Thanks for your time btw**

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [November 19, 2026, 2:01pm UTC](https://discuss.codemirror.net/t/selection-bug/9145/6 "2026-11-19T14:01:29Z")

</div>

Not sure how I lost track of this thread, but in case anyone is still interested: The issue is that you’re wrapping content text in an `inline-block` styled element, which is something that’s not supported in CodeMirror.
