-
Notifications
You must be signed in to change notification settings - Fork 0
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
[CLOSED] Add feature. Open line above/below the current line. #2588
Comments
I wonder if this feature is common enough that we'd want it in core, or if it'd be better to have it as an optional extension... It seems easy to move out into an extension if desired. It does seem to be in Sublime, though, so that's one data point in favor of core. If we're going to take it in core, can you add unit tests? |
+1 this is actually a feature I miss regularly. |
This feature is common. It is also in Visual Studio (with the same key bindings), Vim and Emacs. I've started writing unit tests. But, I've a question: How do I set (or get) the number of spaces for indentation before I run my tests?
|
There was a test in the test suite that was setting indentation to 1 space. I just removed that and it was merged yesterday morning. You might try merging from master and see if the problem clears up. If I'm reading things right, you should be able to find out what the indentation is set to by calling |
Thanks dangoor. I've added unit tests. |
Two quick thoughts:
|
It's great to see all of those unit tests. Thanks! One other note: someone on the Brackets core team noted that the Edit menu is getting rather long (and we don't have submenus yet to help with that). Because of that, we should probably land this with just key bindings and not menu entries. |
|
I noticed that opening a line below at the bottom of an inline (CSS) editor doesn't work. This is not a big deal, because you can't really add rules using the existing inline CSS editor, but I thought I'd mention it in case this is not expected behavior. (edit: also doesn't work in JS inline editor...) |
Nice implementation and I appreciate all of the tests. (I'm looking forward to having this myself!) Looking at all of that test code, I kept thinking "there's got to be a way to boil this down a bit", but looking at the code that varies between tests there's really only a couple of lines that are truly duplicated from test to test, so it may be best as it is, which is nice and straightforward. Thanks for pulling this together! |
What do you mean when you say "opening a line below at the bottom of an inline (CSS) editor doesn't work"? How can I reproduce the problem? That problem should have already been fixed in the second to last commit (9d4a186). In order to make unit tests are a bit lighter, the following 3 lines could be put within a function which would take the slice() input parameters. But I'm not really sure if it is a nicer solution, so I'm not going to changed that before hearing your opinion.
|
Thanks for the update. Regarding the tests, I came to the same conclusion you did: it's not worth trying to extract those 3 lines into a function. Here is how you can reproduce the (minor) issue that I see:
Like I said, though, this is a small thing and the feature generally works well for me. I'm not going to merge it in right now, because we're gearing up for the next release and I don't want to introduce risk. There's a big change coming into the repo (codemirror v3) which may require a bit of merging for this. One tip: once you've pushed to a public repo, it's better to not rebase. It's fine rebasing until your code is public, merge as necessary after that. |
This is definitely an issue. But that's really strange, because while trying to figure out what could the real problem be I also tested the MoveLine command and noticed a strange behavior as well:
But, if you repeat the steps with the following code it doesn't happen and the inline editor doesn't close. HTML:
CSS:
|
There is already an issue for the Move Line Up/Down in the inline editors adobe/brackets#1933. I tried a fix on that one by not allowing to move past the last line. There seems to be an issue in the inline editors when replacing beyond the last/first line. |
Thanks By the way, thanks |
There's a change coming to CodeMirror that will likely alter some of how inline editors work. I don't know if that will automatically correct problems at the boundaries of inline editors, but it may.
|
Thanks! |
|
I was just about to merge this and then ran into a problem... This could be related to the CodeMirror v3 integration, which happened between the time you created this feature and now. Here are my steps to reproduce:
There were some changes in CodeMirror 3 with respect to undo and multiple operations. Do you think you can look into this? |
This morning I merged with upstream and tested both OpenLine and MoveLine again. CodeMirror3 doesn't correct the problem. So I decided to refactor the OpenLine code to work around it. Regarding the new ctrl-z problem, it is related to the CodeMirror v3 integration. And I was already working on it. In my last implementation ctrl-z removes the inserted line and indentation in one single step, and the cursor is positioned back at the end of the upper line. At the moment I have no idea whether any efficient way to bring the cursor back at the exact position from before exists. |
Hmm... In the copy that I have, prior to the changes you made, undo actually did restore the cursor position (on the first undo). As I understand it CodeMirror 3 is a bit saner in its undo handling, with respect to selections and such. |
In my previous implementation the operation was handled in 2 different steps: insert a new line using In my last implementation the 2 steps are: At the moment I don't see any effective solution to insert a new line and correctly indent it in a single atomic step (or remove the indentation step from the undo history). I don't exclude that probably I'm not using the right APIs, so I'm open for any good suggestions. Also, having tried several workarounds, it must be said that for now the inline editor problem prevents any implementations from being fully working with the edge case of the last line of the inline editor (at least until it is fixed). So, before I go any further I'll be waiting for your suggestions/decisions. UPDATE: |
My new attempt fixes the undo history, but unexpected behaviors with the inline editors persist. |
Hmm... when I open line in an inline editor now, it positions the cursor at the end of the line following the newly opened line. Is that behavior you're seeing? I hate to say it, but we're working on some tight timelines for getting some new features in over the coming weeks. Because of that, I don't really have time to delve deeper into the problems here. You may be right about there being something else going on with the inline editors, especially now that we've switched to CM3. If you find a case that is broken outside of the new open line command, please file a separate issue on it because that would be higher priority for us than adding openline. I do, personally, want to see this command land, but don't have the time right now to dig in. (I also don't have much experience with the intricacies of inline editors, otherwise the answer might be there in front of me.) One other comment after glancing at your latest code: Thanks again for your persistence with this. |
I hope future changes to inline editors could help with this problem. |
With those 2 changes, I think this should work well, since the selection was one of the last broken things, and from some of the testing I did and the tests from the request, everything seems to work well. |
I already tried it before, but something has been changed and now it works! Thanks |
Marking [OPEN] for committers to review. |
Sure, i'll give it a final review. I think the code works good now. |
Wednesday Jan 30, 2013 at 23:52 GMT
Originally opened as adobe/brackets#2729
Keyboard shortcus are Ctrl-Enter and Ctrl-Shift-Enter
zeis included the following code: https://github.com/adobe/brackets/pull/2729/commits
The text was updated successfully, but these errors were encountered: