Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » The make your own code editor challenge.
- bobbybee
- Scratcher
1000+ posts
The make your own code editor challenge.
In a modal editor, save the last action (so last insert, last delete, last whatever) and just invert / revert that. @gtoal, do you have any tips for how to implement undo/redo?
In a non-modal editor, I believe the principle is the same but the divisions of a single “action” is rather less clear cut.
“Ooo, can I call you Señorita Bee?” ~Chibi-Matoran
- BookOwl
- Scratcher
1000+ posts
The make your own code editor challenge.
I've done some research, and it seems that the most common way to do undo/redo is the Command Pattern
who needs signatures
- gtoal
- Scratcher
1000+ posts
The make your own code editor challenge.
Well, in *my* system, where every edit can be represented by a textual edit command, I keep a log of commands executed so far, and then replay that against the original file - so an undo would be to replay all but the last <n> commands. @gtoal, do you have any tips for how to implement undo/redo?
An alternative would be to log the commands which would undo the changes, so if you deleted a character, you would record a command which would insert that character, then to undo you would execute those re-instatement commands in reverse order. this would be like storing the output of the diff command between versions, and undoing by running the ‘patch’ command.
An alternative I've seen is keeping a stack of deletions and having an edit key that pops items off the ‘deleted’ stack. That one was only saving whole lines, not single characters. (there was a ‘delete line’ key) That was more an ‘undelete’ than an ‘undo’ and was also the mechanism which that editor used for moving blocks of text around in the file. (delete, then move, then undelete)
Last edited by gtoal (Feb. 6, 2017 18:37:23)
- NickyNouse
- Scratcher
1000+ posts
The make your own code editor challenge.
Ooh I like that answer. It sounds like an easier solution than writing an inverse function for every possible command, and it makes for less frequent “snapshots” then the previous answer. You could even find ways to consolidate commands (for example, if the cursor doesn't change position between a series of “character entered” commands you could combine them into one “paste” commandWell, in *my* system, where every edit can be represented by a textual edit command, I keep a log of commands executed so far, and then replay that against the original file - so an undo would be to replay all but the last <n> commands. @gtoal, do you have any tips for how to implement undo/redo?
An alternative would be to log the commands which would undo the changes, so if you deleted a character, you would record a command which would insert that character, then to undo you would execute those re-instatement commands in reverse order. this would be like storing the output of the diff command between versions, and undoing by running the ‘patch’ command.
An alternative I've seen is keeping a stack of deletions and having an edit key that pops items off the ‘deleted’ stack. That one was only saving whole lines, not single characters. (there was a ‘delete line’ key) That was more an ‘undelete’ than an ‘undo’ and was also the mechanism which that editor used for moving blocks of text around in the file. (delete, then move, then undelete)
- bobbybee
- Scratcher
1000+ posts
The make your own code editor challenge.
Ooh I like that answer. It sounds like an easier solution than writing an inverse function for every possible command, and it makes for less frequent “snapshots” then the previous answer. You could even find ways to consolidate commands (for example, if the cursor doesn't change position between a series of “character entered” commands you could combine them into one “paste” commandWell, in *my* system, where every edit can be represented by a textual edit command, I keep a log of commands executed so far, and then replay that against the original file - so an undo would be to replay all but the last <n> commands. @gtoal, do you have any tips for how to implement undo/redo?
An alternative would be to log the commands which would undo the changes, so if you deleted a character, you would record a command which would insert that character, then to undo you would execute those re-instatement commands in reverse order. this would be like storing the output of the diff command between versions, and undoing by running the ‘patch’ command.
An alternative I've seen is keeping a stack of deletions and having an edit key that pops items off the ‘deleted’ stack. That one was only saving whole lines, not single characters. (there was a ‘delete line’ key) That was more an ‘undelete’ than an ‘undo’ and was also the mechanism which that editor used for moving blocks of text around in the file. (delete, then move, then undelete)
You could always derive inverse functions… maybe.
“Ooo, can I call you Señorita Bee?” ~Chibi-Matoran
- NickyNouse
- Scratcher
1000+ posts
The make your own code editor challenge.
WolframAlpha: “invert function(a, b) { … }”Ooh I like that answer. It sounds like an easier solution than writing an inverse function for every possible command, and it makes for less frequent “snapshots” then the previous answer. You could even find ways to consolidate commands (for example, if the cursor doesn't change position between a series of “character entered” commands you could combine them into one “paste” commandWell, in *my* system, where every edit can be represented by a textual edit command, I keep a log of commands executed so far, and then replay that against the original file - so an undo would be to replay all but the last <n> commands. @gtoal, do you have any tips for how to implement undo/redo?
An alternative would be to log the commands which would undo the changes, so if you deleted a character, you would record a command which would insert that character, then to undo you would execute those re-instatement commands in reverse order. this would be like storing the output of the diff command between versions, and undoing by running the ‘patch’ command.
An alternative I've seen is keeping a stack of deletions and having an edit key that pops items off the ‘deleted’ stack. That one was only saving whole lines, not single characters. (there was a ‘delete line’ key) That was more an ‘undelete’ than an ‘undo’ and was also the mechanism which that editor used for moving blocks of text around in the file. (delete, then move, then undelete)
You could always derive inverse functions… maybe.
- BookOwl
- Scratcher
1000+ posts
The make your own code editor challenge.
You can now open multiple files in trusty!
who needs signatures
- WooHooBoy
- Scratcher
1000+ posts
The make your own code editor challenge.
I've been thinking about how I want my text editor to work - I'd like it to be a small base but very extensible with plugins. In theory I'd like more than just the basic functionality to be written in plugins that are installed by default.
The problem is Rust is a compiled, statically linked language and I'm not quite sure how to go about plugins
The problem is Rust is a compiled, statically linked language and I'm not quite sure how to go about plugins
considered harmful
- BookOwl
- Scratcher
1000+ posts
The make your own code editor challenge.
You could have people write plugins in I've been thinking about how I want my text editor to work - I'd like it to be a small base but very extensible with plugins. In theory I'd like more than just the basic functionality to be written in plugins that are installed by default.Rhai, and then load the plugins in Rust.
The problem is Rust is a compiled, statically linked language and I'm not quite sure how to go about plugins
who needs signatures
- WooHooBoy
- Scratcher
1000+ posts
The make your own code editor challenge.
This is basically exactly what I need! Thanks!You could have people write plugins in I've been thinking about how I want my text editor to work - I'd like it to be a small base but very extensible with plugins. In theory I'd like more than just the basic functionality to be written in plugins that are installed by default.Rhai, and then load the plugins in Rust.
The problem is Rust is a compiled, statically linked language and I'm not quite sure how to go about plugins
considered harmful
- cloudbridge
- Scratcher
10 posts
The make your own code editor challenge.
I know this is going to be the dumbest entry here but this fits all my needs basically.Paste into URL to usedata:text/html,<h1>The BKFighter Simple Text Editor</h1><input style="height:100%;width:100%"></input>
Features
-You can type in it
-Highly customizable
-If your school blocks the URL you just need to change a few characters to unblock it.
Honestly I'm that guy that doesn't care what the editor looks like or does, but I'd still be interested to see some other people's examples.
Paste this into the URL bar to launch The BKFighter Simple Text Editor.
javascript:document.getElementsByTagName('html')[0].innerHTML = '<h1>The BKFighter Simple Text Editor</h1><input style="height:100%&width:100%"></input>';
I haven't tested it with all browsers. It works in Opera. Likely Chrome, too. I found that I have to type
javascript:
Or click .innerHTML = ‘<h1>The BKFighter Simple Text Editor</h1><input style=“height:100%&width:100%”></input>’;]here
Last edited by cloudbridge (Feb. 9, 2017 18:47:11)
Cloud Bridge coming soon, if ScratchAPI works.
-Qwertysamo
—
http://i.imgur.com/c1lJ327.png
The Inspect Element has made me famous!
(Paste URL to view image)
- cloudbridge
- Scratcher
10 posts
The make your own code editor challenge.
Here
Last edited by cloudbridge (Feb. 9, 2017 18:50:48)
Cloud Bridge coming soon, if ScratchAPI works.
-Qwertysamo
—
http://i.imgur.com/c1lJ327.png
The Inspect Element has made me famous!
(Paste URL to view image)
- cloudbridge
- Scratcher
10 posts
The make your own code editor challenge.
Oh, links don't work until I'm a Scratcher. I can't edit my posts, either.
Cloud Bridge coming soon, if ScratchAPI works.
-Qwertysamo
—
http://i.imgur.com/c1lJ327.png
The Inspect Element has made me famous!
(Paste URL to view image)
- gtoal
- Scratcher
1000+ posts
The make your own code editor challenge.
here.I made a new challenge based on this if you are interested
Rather than writing a programming language, why don't you use the same skills for writing an editing language? (Which was the original point of this thread, though I haven't seen anyone's editor yet that's beyond the type & insert stage…)
G
- IcyCoder
- Scratcher
1000+ posts
The make your own code editor challenge.
Well that challenge does not mean this one is done… it is just another prompthere.I made a new challenge based on this if you are interested
Rather than writing a programming language, why don't you use the same skills for writing an editing language? (Which was the original point of this thread, though I haven't seen anyone's editor yet that's beyond the type & insert stage…)
G
Because JS is the future (echos) future future futur futu fut fu f
- IcyCoder
- Scratcher
1000+ posts
The make your own code editor challenge.
Let me bump this… maybe it can get some life again
Because JS is the future (echos) future future futur futu fut fu f
- herohamp
- Scratcher
1000+ posts
The make your own code editor challenge.
Thanks… Now I feel pressured to try again
- TheMonsterOfTheDeep
- Scratcher
1000+ posts
The make your own code editor challenge.
I recently added a really basic feature to pop that really improves it's usability - pushing ^R will attempt to read from a file in the current directory named “.popdebug” and will pass it's first line to a system() call.
Pop still is in its very early stages, of course - all it is right now is literally a text editing interface, with not even a hint of editing language or anything.
Pop still is in its very early stages, of course - all it is right now is literally a text editing interface, with not even a hint of editing language or anything.
my latest extension: 2d vector math
- IcyCoder
- Scratcher
1000+ posts
The make your own code editor challenge.
Oh sorry Thanks… Now I feel pressured to try again
Because JS is the future (echos) future future futur futu fut fu f
- Discussion Forums
- » Advanced Topics
- » The make your own code editor challenge.