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 tab key usage to try-it editor #3342

Closed
wants to merge 1 commit into from

Conversation

colelawrence
Copy link

Use the tab character in the try-it editor's textbox

@colelawrence
Copy link
Author

Try the demo here: http://zombiehippie.github.io/coffee-script/

e.preventDefault()
textbox = e.target
# Insert tab character at caret or in selection
textbox.value = textbox.value[0...textbox.selectionStart] + "\t" + textbox.value[textbox.selectionEnd...]
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd strongly prefer " "

Copy link

Choose a reason for hiding this comment

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

I'd strongly prefer " "

Why?

I guess I'd prefer "\t" because it will be preserved when you copy-paste it.

@xixixao
Copy link
Contributor

xixixao commented Jan 30, 2014

But it would be a better idea to go all the way and use CodeMirror (if Ace is not an option), as mentioned in other issue.

@colelawrence
Copy link
Author

Well considering the time it takes to implement CodeMirror, this is a great quick addition.
Secondly, you can type two spaces if you prefer(that's how it was before), but pressing tab didn't do anything before.

@xixixao
Copy link
Contributor

xixixao commented Jan 30, 2014

@zombiehippie It did make the textarea lose focus. 2 spaces are preferred indentation style for CS (judging from its compiler and unofficial style guide).

@rlidwka
Copy link

rlidwka commented Feb 1, 2014

why isn't Ace an option?

@colelawrence
Copy link
Author

@xixixao we could have a checkbox "Use tabs"
I think it is important to have tab as an option because beginners that use the try it editor may not necessarily follow the 2 space rule. But a check box may work :-)

@rlidwka Ace is definitely an option, but if I were implementing this I would use CodeMirror, which is a lot smaller library, because I use it a lot and know it has great documentation (not to say Ace doesn't also) Plus CodeMirror v4 is going to have multiselection) After tweaking the styles and functions of CodeMirror to my liking, I've found there to be little difference between Ace and CodeMirror (besides multiselect obv.) In fact I've already made a coffeescript try it editor with codemirror that you can try and see the src of. ZombieHippie/Quick-Test-CoffeeScript/gh-pages

It would be optimal if the ide had a "Use-tabs" option also.

@xixixao
Copy link
Contributor

xixixao commented Feb 2, 2014

@zombiehippie Finally, this makes CodeMirror viable again!

Definitely no option and if beginner is visiting they should definitely be introduced to the correct style. 2 spaces, no guesses there. If you want to change tab style you should be using some better deployment of the editors or a desktop editor. Try and run should be kept as simple as it is now.

@rlidwka
Copy link

rlidwka commented Feb 2, 2014

Definitely no option and if beginner is visiting they should definitely be introduced to the correct style.

When I press "tab", I usually expect "tab", not two spaces.

If you want indent width to be equal to 2 spaces, that's fine, just set textarea { tab-size: 2 }. That's what tabs are for. ;)

@xixixao
Copy link
Contributor

xixixao commented Feb 2, 2014

2 spaces are preferred indentation style for CS (judging from its compiler and unofficial style guide).

I don't know what else I can argue here. I suspect that the over hundred contributors to this project have mostly used the tab key on their keyboards to indent code, as do millions of others in other projects.

@colelawrence
Copy link
Author

@xixixao I guess someone could just convert indentation to spaces, check their syntax/experiment, and then convert back to tabs if they wanted. That is a easy to use feature of Sublime Text.

I personally use tab indentation for every project I have, I obviously would not be benefitted by having abother CodeMirror/Ace editor that doesn't support the tab char.

@colelawrence
Copy link
Author

@xixixao oh! What if the default behaviour of the tab key was two spaces, and then shift+tab was the tab character?

@xixixao
Copy link
Contributor

xixixao commented Feb 2, 2014

shift+tab is used for dedentation, again, widely. I appreciate the enthusiasm, I will have a look at how much effort it would be to add CodeMirror4 to the site. Let's close this off for now in favor of a proper solution.

@colelawrence
Copy link
Author

@xixixao Triple check CM4 for syntax highlighting issues. That's the one thing that prevents me from implementing it into my occupational projects. I highly recommend looking at how I implemented CodeMirror to save you some time!

CTRL+] and CTRL+[ for indentation is supported also as demonstrated on most every editor ST, Ace, CM, etc.

@vendethiel
Copy link
Collaborator

Would be cool if CM4 was lazy loaded ;). I don't want it on mobile view, it'd hurt too much

@srgraham
Copy link

srgraham commented Nov 8, 2016

Are there any plans to implement something like this? I usually go to the coffeescript site when testing random quick things, and I usually have a moment of confusion when tab doesn't do what I expect it to do.

GeoffreyBooth added a commit to GeoffreyBooth/coffeescript that referenced this pull request Nov 19, 2016
@GeoffreyBooth GeoffreyBooth mentioned this pull request Nov 19, 2016
GeoffreyBooth added a commit that referenced this pull request Nov 21, 2016
* The generated JavaScript for the examples in the docs ends up within index.html, so we don’t need the intermediate generated .js files committed in the repo; also, even while .gitignored they should be under `docs`, with the rest of the generated files, not under `documentation`, where the source files are.

* Add “Existential Operator” to the table of contents. Closes #4361

* Updated output due to newer version of highlight.js

* Generated the JavaScript for the docs examples should be synchronous, so that index.html isn’t generated before the JavaScript is

* In “Try CoffeeScript,” if you press the tab key it should type a tab character. Closes #3342.

* Rename doc example folders from `js` and `coffee` to just `examples`

* Add missing `yield` to the list of keywords to highlight until highlight.js catches up; update the class used to match highlight.js’ `keyword`

* `cake doc:site` should watch the example files too, not just index.html.js

* Remove examples folder, including underscore.coffee; remove link to annotated underscore.coffee
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.

5 participants