Skip to content
Discussion options

You must be logged in to vote

Hello @ZeroPoint095

Sorry for sounding dumb but what about just destroy the old codemirror instance and start off with a new one?

from nicegui import ui


@ui.page('/')
def page():
    with ui.column().classes('w-full') as editor_container:
        editor = ui.codemirror('initial', line_wrapping=True)

    def force_set_text(text: str):
        nonlocal editor
        editor_container.clear()
        with editor_container:
            editor = ui.codemirror(text, line_wrapping=True)

    ui.button('set text', on_click=lambda: editor.set_value('set text'))  # can undo
    ui.button('force set text', on_click=lambda: force_set_text('force set text'))  # cannot undo


ui.run(show=False)

Blun…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@ZeroPoint095
Comment options

@evnchn
Comment options

evnchn Dec 8, 2025
Collaborator

Answer selected by ZeroPoint095
Comment options

You must be logged in to vote
1 reply
@ZeroPoint095
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants