Skip to content

Conversation

@ahuang11
Copy link
Contributor

@ahuang11 ahuang11 commented Oct 23, 2025

Closes #8260

Previously, the text would all be selected after replace; this PR prevents that and keeps scroll position after replace.

replace.mp4
import panel as pn
import param


class Editor(param.Parameterized):
    def __init__(self, **kwrgs):
        self.editor = pn.widgets.CodeEditor(value="foo")
        self.cb = pn.state.add_periodic_callback(self.update_editor, period=3000)
        super().__init__(**kwrgs)

    def update_editor(self):
        s = self.editor.value
        s = "bar".join(s.split("foo"))
        self.editor.value = s

    def view(self):
        template = pn.template.FastListTemplate(
            site="FooEditor",
            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)

Be sure to panel build panel and refresh cache!

@holovizbot
Copy link

This pull request has been mentioned on HoloViz Discourse. There might be relevant details there:

https://discourse.holoviz.org/t/ace-editor-selects-all-text-on-assignment/2737/6

@codecov
Copy link

codecov bot commented Oct 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.35%. Comparing base (8eb0b14) to head (3a33d0e).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #8262       +/-   ##
===========================================
+ Coverage   70.20%   85.35%   +15.15%     
===========================================
  Files         347      348        +1     
  Lines       54092    54125       +33     
===========================================
+ Hits        37973    46200     +8227     
+ Misses      16119     7925     -8194     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ahuang11 ahuang11 changed the title Prevent text from being selected after replace Prevent text from being fully selected after replace value Oct 27, 2025
@ahuang11 ahuang11 requested a review from philippjfr October 27, 2025 18:44
@ahuang11 ahuang11 marked this pull request as ready for review October 27, 2025 18:45
@ahuang11 ahuang11 added the type: enhancement Minor feature or improvement to an existing feature label Oct 27, 2025
@philippjfr philippjfr merged commit fe53be4 into main Oct 29, 2025
31 of 40 checks passed
@philippjfr philippjfr deleted the fix_highlight_code branch October 29, 2025 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement Minor feature or improvement to an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants