yhirose / cpp-peglib

A single file C++ header-only PEG (Parsing Expression Grammars) library
MIT License
880 stars 112 forks source link

New playground need resize editors when opening/closing options #212

Closed mingodad closed 2 years ago

mingodad commented 2 years ago

Testing this grammar in the playgound:

start <- _ (STRING_LONG _ / STRING_SHORT _)* !.
_   <- [ \t\n\r]*
STRING_LONG <- '[' ':'+ '['  ( ! (']' ':'+ ']') . )* ']' ':'+ ']'
STRING_SHORT <- ['"] (!['"] .)* ['"]

And this input:

[::[]=]::]

[::[[===[[=[]]=][====[]]===]===]::]

[::::[[===[[=[]]=][====[]]===]===]::::]

[:[]]]]]]]]]:]

[:::[
x y z [==[ blu foo
]==
]
]=]==]
error error]=]:::]

[::[a]===]]=]aaaaaaaaa=]=]=]::]

"dad"

"fast"

'clean'

'bottom'

On my browser the text after "fast" is not shown because the editor doesn't have the same length of it's parent. The same happen to AST, Optmized AST, ...

Probably resizing the editors to the length of it's parents (also after opening/closing AST, ... ) will solve the problem.

yhirose commented 2 years ago

Thank you for the feedback. You can scroll the hidden text into view, right? If so, I don't feel that is necessary.

mingodad commented 2 years ago

It'll make several users confused and probably trigger issues related to this.

mingodad commented 2 years ago

After search a bit I found this https://stackoverflow.com/a/57166828 and with the changes shown bellow it seems to work fine:

diff --git a/docs/index.js b/docs/index.js
index d85b46c..6d8d0fa 100644
--- a/docs/index.js
+++ b/docs/index.js
@@ -152,6 +152,14 @@ $('#auto-refresh').on('change', () => {
 });
 $('#parse').on('click', parse);

+//Resize editors to fit their parents
+function resizeEditorsToParent() {
+   code.resize(); code.renderer.updateFull();
+   codeAst.resize(); codeAst.renderer.updateFull();
+   codeAstOptimized.resize(); codeAstOptimized.renderer.updateFull();
+   codeProfile.resize(); codeProfile.renderer.updateFull();
+}
+
 // Show windows
 function setupToolWindow(lsKeyName, buttonSel, codeSel) {
   let show = localStorage.getItem(lsKeyName) === 'true';
@@ -162,6 +170,7 @@ function setupToolWindow(lsKeyName, buttonSel, codeSel) {
     show = !show;
     localStorage.setItem(lsKeyName, show);
     $(codeSel).css({ 'display': show ? 'block' : 'none' });
+    resizeEditorsToParent();
   });
 }
 setupToolWindow('show-ast', '#show-ast', '#code-ast');
yhirose commented 2 years ago

Thanks! I merged the code.