From 8bd387e8b2322bb9ce7d5a1171b3d3810baff135 Mon Sep 17 00:00:00 2001 From: Juan Tejada Date: Thu, 28 Jan 2016 00:02:55 -0800 Subject: [PATCH] Update OutlineViewItem to focus end of input when editing --- internal_packages/account-sidebar/lib/sidebar-item.coffee | 1 + .../account-sidebar/lib/sidebar-section.coffee | 1 + src/components/outline-view-item.jsx | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/internal_packages/account-sidebar/lib/sidebar-item.coffee b/internal_packages/account-sidebar/lib/sidebar-item.coffee index f72c13603..dcf4aecb9 100644 --- a/internal_packages/account-sidebar/lib/sidebar-item.coffee +++ b/internal_packages/account-sidebar/lib/sidebar-item.coffee @@ -42,6 +42,7 @@ onDeleteItem = (item) -> Actions.queueTask(new DestroyCategoryTask({category})) onEditItem = (item, value) -> + return unless value return if item.deleted is true category = item.perspective.category() return unless category diff --git a/internal_packages/account-sidebar/lib/sidebar-section.coffee b/internal_packages/account-sidebar/lib/sidebar-section.coffee index fcc41ca57..de757fee3 100644 --- a/internal_packages/account-sidebar/lib/sidebar-section.coffee +++ b/internal_packages/account-sidebar/lib/sidebar-section.coffee @@ -139,6 +139,7 @@ class SidebarSection collapsed: collapsed onToggleCollapsed: onToggleCollapsed onItemCreated: (displayName) -> + return unless displayName category = new Category displayName: displayName accountId: account.id diff --git a/src/components/outline-view-item.jsx b/src/components/outline-view-item.jsx index 9dcf041df..d87c46b50 100644 --- a/src/components/outline-view-item.jsx +++ b/src/components/outline-view-item.jsx @@ -130,6 +130,11 @@ class OutlineViewItem extends Component { this.setState({editing: true}); } + _onInputFocus = (event)=> { + const input = event.target; + input.selectionStart = input.selectionEnd = input.value.length; + } + _onInputBlur = (event)=> { this._clearEditingState(event); } @@ -202,6 +207,7 @@ class OutlineViewItem extends Component { placeholder={placeholder} defaultValue={item.name} onBlur={this._onInputBlur} + onFocus={this._onInputFocus} onKeyDown={this._onInputKeyDown} /> ); }