Skip to content
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

Place cursor after the TODO keyword when creating a new header #193

Merged
merged 2 commits into from
Jan 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/components/OrgFile/components/TitleLine/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class TitleLine extends PureComponent {
'handleTextareaRef',
'handleTitleClick',
'handleTextareaBlur',
'handleTextareaFocus',
'handleTitleChange',
'handleTitleFieldClick',
'handleTodoClick',
Expand Down Expand Up @@ -136,6 +137,16 @@ class TitleLine extends PureComponent {
}, 0);
}

handleTextareaFocus(event) {
const { header } = this.props;
const rawTitle = header.getIn(['titleLine', 'rawTitle']);
if (rawTitle === '') {
const text = event.target.value;
event.target.selectionStart = text.length;
event.target.selectionEnd = text.length;
}
}

handleTitleChange(event) {
// If the last character typed was a newline at the end, exit edit mode.
const newTitle = event.target.value;
Expand Down Expand Up @@ -235,6 +246,7 @@ class TitleLine extends PureComponent {
ref={this.handleTextareaRef}
value={this.state.titleValue}
onBlur={this.handleTextareaBlur}
onFocus={this.handleTextareaFocus}
onChange={this.handleTitleChange}
onClick={this.handleTitleFieldClick}
/>
Expand Down