Discuss Scratch

bobbybee
Scratcher
1000+ posts

The make your own code editor challenge.

BookOwl wrote:

@gtoal, do you have any tips for how to implement undo/redo?
In a modal editor, save the last action (so last insert, last delete, last whatever) and just invert / revert that.

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.

BookOwl wrote:

@gtoal, do you have any tips for how to implement undo/redo?
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.

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.

gtoal wrote:

BookOwl wrote:

@gtoal, do you have any tips for how to implement undo/redo?
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.

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)
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” command
bobbybee
Scratcher
1000+ posts

The make your own code editor challenge.

NickyNouse wrote:

gtoal wrote:

BookOwl wrote:

@gtoal, do you have any tips for how to implement undo/redo?
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.

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)
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” command

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.

bobbybee wrote:

NickyNouse wrote:

gtoal wrote:

BookOwl wrote:

@gtoal, do you have any tips for how to implement undo/redo?
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.

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)
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” command

You could always derive inverse functions… maybe.
WolframAlpha: “invert function(a, b) { … }”
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

considered harmful
BookOwl
Scratcher
1000+ posts

The make your own code editor challenge.

WooHooBoy wrote:

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
You could have people write plugins in Rhai, and then load the plugins in Rust.

who needs signatures
WooHooBoy
Scratcher
1000+ posts

The make your own code editor challenge.

BookOwl wrote:

WooHooBoy wrote:

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
You could have people write plugins in Rhai, and then load the plugins in Rust.
This is basically exactly what I need! Thanks!

considered harmful
cloudbridge
Scratcher
10 posts

The make your own code editor challenge.

BKFighter wrote:

I know this is going to be the dumbest entry here but this fits all my needs basically.
data:text/html,<h1>The BKFighter Simple Text Editor</h1><input style="height:100%;width:100%"></input>
Paste into URL to use
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:
at the beginning of the line, after I paste the code.

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)
IcyCoder
Scratcher
1000+ posts

The make your own code editor challenge.

I made a new challenge based on this if you are interested here.

Because JS is the future (echos) future future futur futu fut fu f
gtoal
Scratcher
1000+ posts

The make your own code editor challenge.

IcyCoder wrote:

I made a new challenge based on this if you are interested here.

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.

gtoal wrote:

IcyCoder wrote:

I made a new challenge based on this if you are interested here.

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
Well that challenge does not mean this one is done… it is just another prompt

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
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.

my latest extension: 2d vector math
IcyCoder
Scratcher
1000+ posts

The make your own code editor challenge.

herohamp wrote:

Thanks… Now I feel pressured to try again
Oh sorry

Because JS is the future (echos) future future futur futu fut fu f

Powered by DjangoBB