gorilla-repl
gorilla-repl copied to clipboard
WIP: Lockable free segments
Hi, Jony! :wave:
I was reading #193 and decided to give it a go! So, I wrote a draft! And this is a WIP PR. Do not merge; do not pass GO, do not collect $200; etc.
Current functionality:
- You can "lock" a selected free segment, making it read-only; and
- You can "unlock" a selected free segment, making it editable again.
I'm running into one current, obvious problem, though, which I'm hoping you'll have some input on:
- Although "locked" free segments are read-only, I couldn't find a way to make them read-only without making the markup visible when the segments are selected. Meaning, if a locked segment is selected, the segment will still switch into the CodeMirror editing mode, and the actual Markdown (vs. the formatted text) will still be visible.
I've tried various ways to get around this, especially by just having self.lock in segment.js set self.markupVisible(false); so long as self.locked() == true. But, when I tried that approach, specifically, I ran into the problem of redefining activate and deactivate for locked segments, which was... yargh. Because activate and deactivate currently involve CodeMirror cursors.
Anyway, thoughts? Advice?
Hi, just a quick ping as am on my hols at the moment! Will have a proper look once I'm back :-)
Hi Katherine,
sorry once again for being so slow on getting back to you on this!
Looks good to me, on the whole. A few comments:
- regarding the question of not showing the markup editor: I think it should be possible to adjust the code in the free segment's
self.activateto avoid showing the editor altogether. Pretty much calling onlyself.active(true);would do it I think. I haven't tried this, though, so there might be some problems that I'm not seeing. The segment'sactiveproperty should be the only thing that's needed to make the segment 'cursor' (the pink outline) and the targeting of commands work. - I think now might be the right time to add a general approach to storing segment level metadata. So, rather than use a specific marker to indicate a locked segment, we could have a piece of JSON with all metadata for the cell. We don't necessarily need to implement that now, but perhaps if we build this feature to support it, it would be good. We could just adjust the
lockedTagin the parser to be;; {locked: true}. Or, I wonder whether we could even put the JSON data on the same line as the segment open tag;; **to keep the extra comment lines to a minimum? - If we're changing the file format we really must remember to change the version number. Things could be painful if we forget to do this, so we might as well do it now!
But, yes, looks good, and will be a good feature I think :-)
Jony