Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Implement CM Drag & Drop #9584

Merged
merged 1 commit into from
Jan 8, 2015
Merged

Conversation

marcelgerber
Copy link
Contributor

Implements https://trello.com/c/io24Byhm/910-drag-and-drop-to-move-selected-text-within-editor.
Adds a new pref dragDropText (which is off by default)

@le717
Copy link
Contributor

le717 commented Oct 17, 2014

As if I were not already spoiled on multiple cursors, this will make coding so much better. :D
Did you check the status of #141 after enabling this (as the Trello card you linked refers to)?

@marcelgerber
Copy link
Contributor Author

No, I can't repro that issue.

@TomMalbran
Copy link
Contributor

YAY!!! Thanks!! I hope this can make it into 1.0, please :)

@marcelgerber
Copy link
Contributor Author

I just made sure #141 and #3239 are not reproducible on this branch.

@le717
Copy link
Contributor

le717 commented Nov 30, 2014

Is it too late to get this in 1.1?

@marcelgerber
Copy link
Contributor Author

From my point of view, it's totally fine to merge it now. A test phase of ~7 days should be enough for testing (with various extensions). Also, the diff is actually quite small, so I don't see any problem there.

@TomMalbran
Copy link
Contributor

Bumping. We want this in 1.1. :)

@redmunds redmunds self-assigned this Dec 8, 2014
@@ -123,6 +125,7 @@ define(function (require, exports, module) {

PreferencesManager.definePreference(CLOSE_BRACKETS, "boolean", false);
PreferencesManager.definePreference(CLOSE_TAGS, "Object", { whenOpening: true, whenClosing: true, indentTags: [] });
PreferencesManager.definePreference(DRAG_DROP, "boolean", true);
Copy link
Contributor

Choose a reason for hiding this comment

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

This new feature is enabled by default. New features are usually off by default so as to not update current behavior, but I can be swayed by public opinion. What does everyone else think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that it should be enabled by default, since is not a visual feature, or something that changes any behaviour, it just enables a new action of drag and drop. Unless for some reason you were clicking and dragging, this feature shouldn't change anything, and every user that expects to be able to drag and drop text, will not need to change a preference, which are a bit hidden at this moment.

Copy link
Contributor

Choose a reason for hiding this comment

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

I support enabling this default. As a user, I would expect drag-and-drop to be enabled by default. Also what @TomMalbran said.

Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't heard anyone disagree, so I guess it's ok for this new feature to be on by default.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to be on by default.

@redmunds
Copy link
Contributor

redmunds commented Dec 8, 2014

I seem to remember someone saying that dragging text within editor was not enabled because it conflicted with drag and drop of files or folders, but that seems to work ok. Does anyone know of any conflicts that may be created by this?

@redmunds
Copy link
Contributor

redmunds commented Dec 8, 2014

When I drag text, I see a drag cursor, but I was also expecting to see a pointer cursor when hovering over selected text like ST3 and VS. Any reason that was not added?

@marcelgerber
Copy link
Contributor Author

The file-dropping issue is simply fixed by the little event handling code added in this PR.

@redmunds
Copy link
Contributor

redmunds commented Dec 8, 2014

Done with initial code review. It seems like there may be too many remaining questions to get this in for 1.1, so hopefully we'll get it in 1.2.

@marcelgerber
Copy link
Contributor Author

Not showing the pointer cursor is the same thing CM does, and I think this is a CM design decision (or at least, it has to be done in CM).

@redmunds
Copy link
Contributor

Not showing the pointer cursor is the same thing CM does, and I think this is a CM design decision (or at least, it has to be done in CM).

I'd prefer the cursor to change when over selected text, but I can't figure out how to do it with existing DOM. Does anyone else have any opinions about this? cc @larz0 @njx

@njx
Copy link
Contributor

njx commented Dec 11, 2014

You should be able to do it by just making a CSS rule for the selection style that sets the cursor property. But I think we should keep it the way it is, since drag and drop of text is not the 80% use case, and the I-beam is critical for properly targeting the cursor if you don't want to drag and drop (but just want to change the selection to a cursor inside the existing selection). Also, keeping the I-beam seems to be the standard behavior on Mac in this case (tested in TextEdit as well as in native text controls within Chrome, both of which support drag and drop of text). If the standard behavior is different on Windows, we could make a Windows-specific CSS rule for this.

@marcelgerber
Copy link
Contributor Author

So, I tested this with multiple Windows editors I have installed:

  • Sublime Text 2: Pointer cursor
  • Visual Studio Express 2013: Pointer cursor
  • Notepad++: Pointer cursor
  • SciTE: Pointer cursor
  • Atom: No drag & drop

So it looks like this is the de-facto standard on Windows.

@njx
Copy link
Contributor

njx commented Dec 11, 2014

Ah, that makes sense. So yeah, let's make it a Windows-specific rule.

@marcelgerber
Copy link
Contributor Author

@njx I can't get it to work either. Setting the style on .CodeMirror-selected doesn't work.

@njx
Copy link
Contributor

njx commented Dec 11, 2014

Ah, it might be because the selection is drawn behind the text, so doesn't get the events. Probably worth asking Marijn for suggestions on how to fix it if we want to pursue this.

@marcelgerber
Copy link
Contributor Author

@njx I asked him, and that's what I got:
https://twitter.com/marijnjh/status/543164059617857536
https://twitter.com/marijnjh/status/543166258842451968

I don't know, though, if it's worth using that addon.

@njx
Copy link
Contributor

njx commented Dec 11, 2014

Seems fine to me if it doesn't degrade performance significantly.

@marcelgerber
Copy link
Contributor Author

Even with the addon enabled I can't seem to get it to work. I managed to change the text color of selections, but cursor doesn't work for me, while it works perfectly well on the CM demo site.
Any help appreciated.

@redmunds
Copy link
Contributor

@marcelgerber The problem seems to be that containing class .CodeMirror-lines has pointer-events: none;, so pointer-events: auto; needs to be added to new rule. For example:

.platform-win .CodeMirror-selectedtext {
    pointer-events: auto;
    cursor: default;
}

@marcelgerber
Copy link
Contributor Author

Yeah, that worked (but the code is still kind of ugly ;) ).
There's still an issue though - while on selected non-text background (blank line), you still see the normal cursor.

@@ -268,6 +268,11 @@ div.CodeMirror-cursors {
}

.CodeMirror-matchingtag { background: @matching-bracket; }

div.CodeMirror-selected {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we want this on Windows only? (e.g. .platform-win div.CodeMirror-selected).

@marcelgerber
Copy link
Contributor Author

The interesting thing is that, even with the latest commits, I don't always see the pointer cursor. If it doesn't work, I need to restart Brackets in order to get it to work again.

Also, I couldn't fix the "cursor-change-while-dragging" problem, even though I tried all the CSS pseudo classes (like :active, :focus).

In case we can't resolve these issues, I'd rather go with just showing the caret while hovering a selection, even though that's apparently not the OS default.

@TomMalbran
Copy link
Contributor

@marcelgerber You might need to add an additional class to toggle the pointer, and remove it while dragging.

@marcelgerber
Copy link
Contributor Author

I don't think that will fix the first issue.

@redmunds
Copy link
Contributor

redmunds commented Jan 6, 2015

@marcelgerber

I don't think that will fix the first issue.

Are you referring to the "don't always see the pointer cursor" issue? If so, I haven't see that -- got recipe?

@marcelgerber
Copy link
Contributor Author

I can almost reliably repro it like this:

  1. Create a new selection in some file
  2. Restart Brackets
  3. Hover over the selection
  4. If the cursor does change to cursor: default, go back to step 2

@marcelgerber
Copy link
Contributor Author

I opened codemirror/codemirror5#3020 for this to go into CM directly (CM actually manages some other cursors, too, like the crosshair while holding down Alt and the Drag & Drop cursor).
Let's see how far we get.

@redmunds
Copy link
Contributor

redmunds commented Jan 8, 2015

@marcelgerber

In case we can't resolve these issues, I'd rather go with just showing the caret while hovering a selection, even though that's apparently not the OS default.

I'm ok with merging "showing the caret while hovering a selection" for now and address the rest later. If nobody disagrees, let me know when that's ready for a final review. Note that it probably should be squashed.

@marcelgerber
Copy link
Contributor Author

@redmunds Done & rebased. Ready for final review/merge.

@redmunds
Copy link
Contributor

redmunds commented Jan 8, 2015

Looks good. Merging.

redmunds added a commit that referenced this pull request Jan 8, 2015
@redmunds redmunds merged commit 47293e9 into adobe:master Jan 8, 2015
@redmunds
Copy link
Contributor

redmunds commented Jan 8, 2015

@marcelgerber Reminder: add new preference here

@marcelgerber marcelgerber deleted the cm-drag-drop branch January 8, 2015 19:23
@le717
Copy link
Contributor

le717 commented Jan 8, 2015

@marcelgerber
Copy link
Contributor Author

Good news:
Marijn wrote an addon to show a different cursor on selection mouseover, so we can start using that in the next Release (I got a branch ready already 👍)
codemirror/codemirror5#3020 (comment)

@RB-Lab
Copy link

RB-Lab commented Mar 4, 2015

Just wanna mention that I recently updated Brackets to version 1.2 on my OS X (didn't try it on Linux yet) and had no this feature (I waited so much) enabled by default. In my preferences file there was no such preference. So I had to add it there manually and it calls dragDropText, not dragDrop as it said in the very first comment. Just in case somebody faced the same problem... (maybe there is some better place to say this, but link from Release Notes let me here)

@marcelgerber
Copy link
Contributor Author

To avoid confusion, I just edited the first post to include the actual pref name and that it's off by default ;)

@peterflynn
Copy link
Member

The release notes and the update notification also both make it clear you need to change a pref to enable this, and call out the pref by name...

@sathyamoorthi
Copy link
Contributor

@marcelgerber I'm not sure whether you are aware of this issue. But drag and drop is not working with PHP files. I tried with js, html, txt, css, less and py files. All are working fine.

@marcelgerber
Copy link
Contributor Author

@sathyamoorthi It definitely works for me, even in PHP files. Could you try it again with extensions disabled?

@peterflynn
Copy link
Member

@sathyamoorthi Can you file a new bug so we can track this? This PR is already closed.

@sathyamoorthi
Copy link
Contributor

@marcelgerber Yes. It is working fine without extensions. Thx.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.