mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-27 15:08:20 +01:00
Improve insert behavior for drag-and-drop and paste uploads
Summary: In Safari, Firefox and Chrome, respect cursor position and selection ranges. Test Plan: Dragged-and-dropped files into the middle of text, end of text, and a selected text range in Safari, Firefox and Chrome. Copy/pasted files into similar cases in Chrome. Got expected, normal behavior in all cases. Reviewers: btrahan, vrana, jungejason Reviewed By: btrahan CC: aran Maniphest Tasks: T1016 Differential Revision: https://secure.phabricator.com/D2155
This commit is contained in:
parent
23fd936b47
commit
06367c4801
2 changed files with 57 additions and 37 deletions
|
@ -760,7 +760,7 @@ celerity_register_resource_map(array(
|
|||
),
|
||||
'javelin-behavior-aphront-drag-and-drop-textarea' =>
|
||||
array(
|
||||
'uri' => '/res/65980508/rsrc/js/application/core/behavior-drag-and-drop-textarea.js',
|
||||
'uri' => '/res/43f964a7/rsrc/js/application/core/behavior-drag-and-drop-textarea.js',
|
||||
'type' => 'js',
|
||||
'requires' =>
|
||||
array(
|
||||
|
@ -2470,7 +2470,7 @@ celerity_register_resource_map(array(
|
|||
'uri' => '/res/pkg/216b9542/differential.pkg.css',
|
||||
'type' => 'css',
|
||||
),
|
||||
'4d8b2d16' =>
|
||||
'a3cabbba' =>
|
||||
array(
|
||||
'name' => 'differential.pkg.js',
|
||||
'symbols' =>
|
||||
|
@ -2493,7 +2493,7 @@ celerity_register_resource_map(array(
|
|||
15 => 'javelin-behavior-differential-dropdown-menus',
|
||||
16 => 'javelin-behavior-buoyant',
|
||||
),
|
||||
'uri' => '/res/pkg/4d8b2d16/differential.pkg.js',
|
||||
'uri' => '/res/pkg/a3cabbba/differential.pkg.js',
|
||||
'type' => 'js',
|
||||
),
|
||||
'4ccda8a6' =>
|
||||
|
@ -2583,7 +2583,7 @@ celerity_register_resource_map(array(
|
|||
'aphront-typeahead-control-css' => 'c7d9f973',
|
||||
'differential-changeset-view-css' => '216b9542',
|
||||
'differential-core-view-css' => '216b9542',
|
||||
'differential-inline-comment-editor' => '4d8b2d16',
|
||||
'differential-inline-comment-editor' => 'a3cabbba',
|
||||
'differential-local-commits-view-css' => '216b9542',
|
||||
'differential-revision-add-comment-css' => '216b9542',
|
||||
'differential-revision-comment-css' => '216b9542',
|
||||
|
@ -2594,27 +2594,27 @@ celerity_register_resource_map(array(
|
|||
'diffusion-commit-view-css' => '4ccda8a6',
|
||||
'javelin-behavior' => '4fbae2af',
|
||||
'javelin-behavior-aphront-basic-tokenizer' => '2af849fb',
|
||||
'javelin-behavior-aphront-drag-and-drop' => '4d8b2d16',
|
||||
'javelin-behavior-aphront-drag-and-drop-textarea' => '4d8b2d16',
|
||||
'javelin-behavior-aphront-drag-and-drop' => 'a3cabbba',
|
||||
'javelin-behavior-aphront-drag-and-drop-textarea' => 'a3cabbba',
|
||||
'javelin-behavior-aphront-form-disable-on-submit' => '21d01ed8',
|
||||
'javelin-behavior-buoyant' => '4d8b2d16',
|
||||
'javelin-behavior-differential-accept-with-errors' => '4d8b2d16',
|
||||
'javelin-behavior-differential-add-reviewers-and-ccs' => '4d8b2d16',
|
||||
'javelin-behavior-differential-comment-jump' => '4d8b2d16',
|
||||
'javelin-behavior-differential-diff-radios' => '4d8b2d16',
|
||||
'javelin-behavior-differential-dropdown-menus' => '4d8b2d16',
|
||||
'javelin-behavior-differential-edit-inline-comments' => '4d8b2d16',
|
||||
'javelin-behavior-differential-feedback-preview' => '4d8b2d16',
|
||||
'javelin-behavior-differential-keyboard-navigation' => '4d8b2d16',
|
||||
'javelin-behavior-differential-populate' => '4d8b2d16',
|
||||
'javelin-behavior-differential-show-more' => '4d8b2d16',
|
||||
'javelin-behavior-buoyant' => 'a3cabbba',
|
||||
'javelin-behavior-differential-accept-with-errors' => 'a3cabbba',
|
||||
'javelin-behavior-differential-add-reviewers-and-ccs' => 'a3cabbba',
|
||||
'javelin-behavior-differential-comment-jump' => 'a3cabbba',
|
||||
'javelin-behavior-differential-diff-radios' => 'a3cabbba',
|
||||
'javelin-behavior-differential-dropdown-menus' => 'a3cabbba',
|
||||
'javelin-behavior-differential-edit-inline-comments' => 'a3cabbba',
|
||||
'javelin-behavior-differential-feedback-preview' => 'a3cabbba',
|
||||
'javelin-behavior-differential-keyboard-navigation' => 'a3cabbba',
|
||||
'javelin-behavior-differential-populate' => 'a3cabbba',
|
||||
'javelin-behavior-differential-show-more' => 'a3cabbba',
|
||||
'javelin-behavior-maniphest-batch-selector' => '86fc0b0c',
|
||||
'javelin-behavior-maniphest-transaction-controls' => '86fc0b0c',
|
||||
'javelin-behavior-maniphest-transaction-expand' => '86fc0b0c',
|
||||
'javelin-behavior-maniphest-transaction-preview' => '86fc0b0c',
|
||||
'javelin-behavior-phabricator-autofocus' => '21d01ed8',
|
||||
'javelin-behavior-phabricator-keyboard-shortcuts' => '21d01ed8',
|
||||
'javelin-behavior-phabricator-object-selector' => '4d8b2d16',
|
||||
'javelin-behavior-phabricator-object-selector' => 'a3cabbba',
|
||||
'javelin-behavior-phabricator-watch-anchor' => '21d01ed8',
|
||||
'javelin-behavior-refresh-csrf' => '21d01ed8',
|
||||
'javelin-behavior-workflow' => '21d01ed8',
|
||||
|
@ -2642,7 +2642,7 @@ celerity_register_resource_map(array(
|
|||
'phabricator-core-buttons-css' => 'c7d9f973',
|
||||
'phabricator-core-css' => 'c7d9f973',
|
||||
'phabricator-directory-css' => 'c7d9f973',
|
||||
'phabricator-drag-and-drop-file-upload' => '4d8b2d16',
|
||||
'phabricator-drag-and-drop-file-upload' => 'a3cabbba',
|
||||
'phabricator-dropdown-menu' => '21d01ed8',
|
||||
'phabricator-jump-nav' => 'c7d9f973',
|
||||
'phabricator-keyboard-shortcut' => '21d01ed8',
|
||||
|
@ -2651,7 +2651,7 @@ celerity_register_resource_map(array(
|
|||
'phabricator-object-selector-css' => '216b9542',
|
||||
'phabricator-paste-file-upload' => '21d01ed8',
|
||||
'phabricator-remarkup-css' => 'c7d9f973',
|
||||
'phabricator-shaped-request' => '4d8b2d16',
|
||||
'phabricator-shaped-request' => 'a3cabbba',
|
||||
'phabricator-standard-page-view' => 'c7d9f973',
|
||||
'phabricator-transaction-view-css' => 'c7d9f973',
|
||||
'syntax-highlighting-css' => 'c7d9f973',
|
||||
|
|
|
@ -8,31 +8,51 @@
|
|||
|
||||
JX.behavior('aphront-drag-and-drop-textarea', function(config) {
|
||||
|
||||
var target = JX.$(config.target);
|
||||
|
||||
function onupload(f) {
|
||||
var v = target.value;
|
||||
var insert = '{F' + f.id + '}';
|
||||
|
||||
// NOTE: This works well in Safari, Firefox and Chrome. We'll probably get
|
||||
// less-good behavior on IE, but I think IE doesn't support drag-and-drop
|
||||
// or paste uploads anyway.
|
||||
|
||||
// Set the insert position to the end of the text, so we get reasonable
|
||||
// default behavior.
|
||||
var s = v.length;
|
||||
var e = v.length;
|
||||
|
||||
// If possible, refine the insert position based on the current selection.
|
||||
if ('selectionStart' in target) {
|
||||
s = target.selectionStart;
|
||||
e = target.selectionEnd;
|
||||
}
|
||||
|
||||
// Build the new text.
|
||||
v = v.substring(0, s) + insert + v.substring(e, v.length);
|
||||
// Replace the current value with the new text.
|
||||
target.value = v;
|
||||
|
||||
// If possible, place the cursor after the inserted text.
|
||||
if ('setSelectionRange' in target) {
|
||||
target.focus();
|
||||
target.setSelectionRange(s + insert.length, s + insert.length);
|
||||
}
|
||||
}
|
||||
|
||||
if (JX.PhabricatorDragAndDropFileUpload.isSupported()) {
|
||||
var target = JX.$(config.target);
|
||||
var drop = new JX.PhabricatorDragAndDropFileUpload(target)
|
||||
.setActivatedClass(config.activatedClass)
|
||||
.setURI(config.uri);
|
||||
|
||||
drop.listen('didUpload', function(f) {
|
||||
// TODO: Implement some fancy cursor position stuff in Javelin so we
|
||||
// can drop it in wherever the cursor is.
|
||||
target.value = target.value + "\n{F" + f.id + "}";
|
||||
});
|
||||
|
||||
drop.listen('didUpload', onupload);
|
||||
drop.start();
|
||||
}
|
||||
|
||||
if (JX.PhabricatorPasteFileUpload.isSupported()) {
|
||||
var target = JX.$(config.target);
|
||||
var paste = new JX.PhabricatorPasteFileUpload(target).setURI(config.uri);
|
||||
|
||||
paste.listen('didUpload', function(f) {
|
||||
// TODO: Implement some fancy cursor position stuff in Javelin so we
|
||||
// can drop it in wherever the cursor is.
|
||||
target.value = target.value + '{F' + f.id + '}';
|
||||
});
|
||||
|
||||
var paste = new JX.PhabricatorPasteFileUpload(target)
|
||||
.setURI(config.uri);
|
||||
paste.listen('didUpload', onupload);
|
||||
paste.start();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue