panel icon indicating copy to clipboard operation
panel copied to clipboard

Add on_keyup and value_input for code editor

Open ahuang11 opened this issue 1 year ago • 8 comments

Closes https://github.com/holoviz/panel/issues/5486

Although this is a breaking change, I think it's worth it because if you try to bind a callback that runs the code from value, it triggers on every keystroke... and as you might imagine, writing valid code often requires more than one character change.

import panel as pn

pn.extension()


def callback(value):
    exec(value)

code = pn.widgets.CodeEditor(value="import this")
pn.bind(callback, code.param.value, watch=True)
code.show()

Previously, removing one character would trigger this error:

image

The workaround to this before is having a separate pn.widgets.Button to submit the code, but now, users can simply watch value, or if they want to watch on every keystroke value_input

ahuang11 avatar Jun 13 '24 19:06 ahuang11

Why not have a value_throttled instead?

MarcSkovMadsen avatar Jun 13 '24 19:06 MarcSkovMadsen

value_input is what other Bokeh text widgets use: https://panel.holoviz.org/reference/widgets/TextInput.html https://panel.holoviz.org/reference/widgets/TextAreaInput.html

I see that sliders use value_throttled.

ahuang11 avatar Jun 13 '24 19:06 ahuang11

Codecov Report

Attention: Patch coverage is 52.05479% with 35 lines in your changes missing coverage. Please review.

Project coverage is 81.75%. Comparing base (7c90f7b) to head (c627038). Report is 67 commits behind head on main.

Files Patch % Lines
panel/tests/ui/widgets/test_codeeditor.py 37.50% 35 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6919      +/-   ##
==========================================
- Coverage   81.79%   81.75%   -0.04%     
==========================================
  Files         326      327       +1     
  Lines       48350    48421      +71     
==========================================
+ Hits        39546    39587      +41     
- Misses       8804     8834      +30     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jun 13 '24 20:06 codecov[bot]

This does end up being a fairly major change in behavior. I agree with it but still.

philippjfr avatar Jun 27 '24 22:06 philippjfr

Is there a way to have a flag that reverts back to the old version to smooth the transition?

hoxbro avatar Jun 28 '24 07:06 hoxbro

Or maybe it'd make sense to keep the current behavior with a flag that toggles the new behavior.

ahuang11 avatar Jun 28 '24 16:06 ahuang11

Is there a way to have a flag that reverts back to the old version to smooth the transition?

I think this is a good suggestion to prevent breaking changes so I have implemented a flag that de-syncs value from value_input, i.e. update value only on loss of focus / command hotkey.

ahuang11 avatar Jun 28 '24 18:06 ahuang11

Test failure seems unrelated

timeout waiting for merge ref

Oh might be https://www.githubstatus.com/

ahuang11 avatar Jun 28 '24 18:06 ahuang11

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Sep 09 '25 22:09 github-actions[bot]