Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Shift+Return shortcut to the code editor that auto-closes a block #1721

Merged
merged 1 commit into from
Dec 17, 2021

Conversation

blinry
Copy link
Contributor

@blinry blinry commented Dec 6, 2021

This is a convenience feature shamelessly stolen from PICO-8: when pressing Shift+Return in the code editor, insert an end statement, and put the cursor in an indented line in-between. For example, we go from

 for x=0,239 do|

to

for x=0,239 do
 |
end

I would love to use this during speedcoding! Is this a welcome feature? Does this PR look alright?

@@ -1157,6 +1157,19 @@ static void doTab(Code* code, bool shift, bool crtl)
else inputSymbolBase(code, '\t');
}

// Add an "end" keyword, and put the cursor in the line between.
static void newLineWithEnd(Code* code)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIC-80 also supports other scripts langs like JS, Squirrel, Wren, Fennel, and Moonscript. Please add the function "end" depending on lang, you can define it in tic_script_config struct (for example const char* end = tic_core_script_config(tic)->functionEnd;).
Thank you.

@nesbox
Copy link
Owner

nesbox commented Dec 11, 2021

Any progress here?

For example, in Ruby and Lua, it would insert an "end" keyword, and
place the cursor in an indented line between.
@blinry
Copy link
Contributor Author

blinry commented Dec 16, 2021

Good point about the multiple langs! I called the struct entry blockEnd, because it could also be used to close if statements and for loops, for example.

For Lua and Ruby, it's end, for JS, Squirrel and Wren, it's }, and Moon and Fennel just insert an indented line for now.

Ready for review again! :)

@blinry blinry changed the title Add Shift+Return shortcut to the code editor that adds a matching "end" Add Shift+Return shortcut to the code editor that auto-closes a block Dec 16, 2021
Copy link
Owner

@nesbox nesbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you 👍

@nesbox nesbox merged commit e1fe882 into nesbox:master Dec 17, 2021
nesbox added a commit that referenced this pull request Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants