Skip to content

Commit

Permalink
Merge pull request #2219 from drgrice1/codemirror-refresh-on-resize
Browse files Browse the repository at this point in the history
Refresh the code mirror window when its containing div resizes.
  • Loading branch information
pstaabp authored Oct 6, 2023
2 parents 4eaeb7d + 2e3b07c commit fb25f23
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions htdocs/js/PGCodeMirror/pgeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@
= CodeMirror.fromTextArea(document.querySelector('.codeMirrorEditor'), options);
cm.setSize('100%', '550px');

// Refresh the CodeMirror instance anytime the containing div resizes so that if line wrapping changes,
// the mouse cursor will still go to the correct place when the user clicks on the CodeMirror window.
new ResizeObserver(() => cm.refresh()).observe(document.querySelector('.CodeMirror'));

const currentThemeFile = localStorage.getItem('WW_PGEditor_selected_theme') ?? 'default';
const currentThemeName = await loadConfig(currentThemeFile);
cm.setOption('theme', currentThemeName);
Expand Down

0 comments on commit fb25f23

Please sign in to comment.