Skip to content

Changing the value of a CodeEditor causes all text to be selected #8260

@j-carson

Description

@j-carson

ALL software version info

I am running the example with uv run --with panel==1.8.2 --python=3.12

Description of expected behavior and the observed behavior

When the contents of a code editor widget are updated, the new text is entirely selected. So, if the user touches their keyboard, all of the text is lost. Changing the displayed text should not cause a "select all"

Complete, minimal, self-contained example code that reproduces the issue

This example updates the text in the CodeEditor every 3 seconds. When that happens, all of the text becomes selected.

import panel as pn
import param

pn.extension('codeeditor')


class Editor(param.Parameterized):
    def __init__(self, **kwrgs):

        self.count = 0
        self.editor = pn.widgets.CodeEditor(value="my clock has ticked 0 times")
        self.cb = pn.state.add_periodic_callback(self.update_editor, period=3000)

        super().__init__(**kwrgs)

    def update_editor(self):
        self.count += 1
        self.editor.value = f"my clock has ticked {self.count} times"

    def view(self):
        template = pn.template.FastListTemplate(
            site="CountTicks",
            title="v1",
            main=[
                pn.Column(self.editor),
            ],
            main_max_width="768px",
        )

        return template


def get_editor():
    editor = Editor()
    return editor.view()


# Start server
pn.serve(get_editor, port=9999, websocket_origin="*", verbose=True)

Stack traceback and/or browser JavaScript console output

Screenshots or screencasts of the bug in action

  • I may be interested in making a pull request to address this

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions