-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
[wip] Feature/elastictabstops #1152
Conversation
BTW I want to hook into the |
cool!
var inChange
editor.on("change",function(e){
if (inChange) {
// called because of changes from this function
return
}
inChange = true
editor.session.replace(range, value)
inChange = false
}) another way is to collect change event and to call $adjustRow after a samll timeout
|
Barev @nightwing . This is getting closer to finishing. The last thing to test is multiple cursors. I have a strange bug with the UndoManager, seen in this video: http://screencast.com/t/4D2BAxmHhrCS After hitting Edit: I mean, I know I can manually deselect via the API. I suspect this is expected behavior, but I think I should change the code to prevent this. |
it's an old bug in https://github.com/ajaxorg/ace/blob/master/lib/ace/edit_session.js#L1284 it definitely shouldn't merge not overlapping range selecting inserted text isn't useful after one character undo, but somewhat useful after deleting word |
The Sublime Text package this is based on is not a proper implementation of my invention. See SublimeText/ElasticTabstops#4 |
Hi @nickgravgaard — I was about to continue our e-mail chain but this PR seems more appropriate. Yeah, I hate to be the bearer of bad news, but I'm doing the same thing as the ST implementation--inserting and removing spaces: https://github.com/ajaxorg/ace/blob/7bbd0177314eddf8220ba0a92f10d0470c036f93/lib/ace/elastic_tabstops.js#L214-226 But, I'm committed to making this function the way you see fit. Another reason I wanted to do this was because I believe someone wanted (or someone was working on) proportional fonts, so I'd like this to work with that. Here's how the Ace API works: Each tab area is actually an arrow character (that takes up one space), followed by a set of I suspect that, due to the crazy nature of tabs and websites, we're also out of luck in proper implementation. But I'd love your feedback nonetheless. |
Actually, from the look of that markup I think it may well be possible to do elastic tabstops properly. Let's consider line 19 from your screenshot and let's say the contents of the buffer for that line are "\tkey_t\tkey;\n". I think you would have a span containing "\t", followed by a span containing "key_t\t" and then a span containing "key;" (possibly with a "\n" on the end). You then just need to position the spans horizontally (and change their widths) using CSS so that they line up with matching "cells" on neighbouring lines. Does that make sense? |
Yeah, I see how that could work. So instead of modifying the buffer directly, add a CSS class to the spans in the rows and modify them that way. I'm trying to think if that will imply some performance loss but I'll try it out first and see how it behaves. |
Unfortunately I am having a hell of a time doing this "properly". Any attempt I make to fake the tab stop spacing results in a horrendous mess, especially as you scroll out of view. I think the current spaces implementation is good enough so @nightwing if you want to review and comment that would be great. I can fix up any issues you find. |
Ah, that's a shame :( Could you rename this feature "elastic tabstops lite" to avoid any confusion with the real thing? See http://nickgravgaard.com/elastictabstops/news/elastic-tabstops-lite/ |
@@ -449,6 +449,21 @@ var Editor = function(renderer, session) { | |||
|
|||
// update cursor because tab characters can influence the cursor position | |||
this.$cursorChange(); | |||
|
|||
if (this.$useElasticTabstops) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this must go into separate function in elastic_tabstops.js
editor must know nothing about elastic tabstops,
insead of editor.setUseElasticTabstops(true)
one should do
var ElasticTabstops = require("ace/elastic_tabstops").ElasticTabstops;
new ElasticTabstops(editor);
@gjtorikian sorry for such a long delay, i needed to finish pr for config.defineOptions first. |
[wip] Feature/elastictabstops
Addresses #215.
I became interested in elastic tabstops after taking a look at the issue above:
Since I'm a masochist (and I didn't feel like looking at Nick's Java code), I actually took a peak at this Python/Sublime text plugin, and did a port of that instead.
It's mostly working at this point. Remaining issues include:
The reason I'm opening this PR now is to ask @nightwing / @fjakobs questions on preferences for conventions.
This feature adds quite a few utility (
$
) functions. Is it preferred to stick them in a file somewhere, instead of littering editor.js with them ? On top of that, this only really works when a real\t
is used. I'm not sure if that's a limitation or a "feature."I would also like to make a better tab character, one that stretches across the width of the span. A "solution" I came up with was to use 2D transforms to stretch the arrow:
Unfortunately, this causes interference with certain characters. The other route is to use a background image, but I am really lazy to create separate light and dark pictures. Plus, I would love to just be able to automatically use the same color as a comment. Is this possible, do you think?
As an added bonus, I am absolutely ashamed at the state of the API docs, there's quite a few missing or inaccurate info. I fixed a few of the ones I referred to but in a separate PR I'll need to fix it all up properly.