Skip to content

Commit

Permalink
Refresh the code mirror window when its containing div resizes.
Browse files Browse the repository at this point in the history
This fixes issue openwebwork#2218.
  • Loading branch information
drgrice1 authored and somiaj committed Nov 21, 2023
1 parent 2115a33 commit 356b1ac
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 356b1ac

Please sign in to comment.