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

Remove ambiguity in all text movement method names… #1042

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
22 changes: 18 additions & 4 deletions src/cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,18 +356,25 @@ module.exports = class Cursor extends Model {
this.goalColumn = column;
}

// Public: Moves the cursor to the beginning of the line.
// Public: Moves the cursor to the beginning of the screen line.
moveToBeginningOfScreenLine() {
this.setScreenPosition([this.getScreenRow(), 0]);
}

// Public: Moves the cursor to the beginning of the buffer line.
//
// Deprecated; prefer {::moveToBeginningOfBufferLine}.
moveToBeginningOfLine() {
this.moveToBeginningOfBufferLine();
}

// Public: Moves the cursor to the beginning of the buffer line.
moveToBeginningOfBufferLine() {
this.setBufferPosition([this.getBufferRow(), 0]);
}

// Public: Moves the cursor to the beginning of the first character in the
// line.
// Public: Moves the cursor to the beginning of the first non-whitespace
// character in the screen line.
moveToFirstCharacterOfLine() {
let targetBufferColumn;
const screenRow = this.getScreenRow();
Expand Down Expand Up @@ -405,13 +412,20 @@ module.exports = class Cursor extends Model {
]);
}

// Public: Moves the cursor to the end of the line.
// Public: Moves the cursor to the end of the screen line.
moveToEndOfScreenLine() {
this.setScreenPosition([this.getScreenRow(), Infinity]);
}

// Public: Moves the cursor to the end of the buffer line.
//
// Deprecated; prefer {::moveToEndOfBufferLine}.
moveToEndOfLine() {
this.moveToEndOfBufferLine();
}

// Public: Moves the cursor to the end of the buffer line.
moveToEndOfBufferLine() {
this.setBufferPosition([this.getBufferRow(), Infinity]);
}

Expand Down
18 changes: 18 additions & 0 deletions src/register-default-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,18 @@ module.exports = function({commandRegistry, commandInstaller, config, notificati
'editor:move-to-beginning-of-line': function() {
return this.moveToBeginningOfLine();
},
'editor:move-to-beginning-of-buffer-line': function() {
return this.moveToBeginningOfBufferLine();
},
'editor:move-to-end-of-screen-line': function() {
return this.moveToEndOfScreenLine();
},
'editor:move-to-end-of-line': function() {
return this.moveToEndOfLine();
},
'editor:move-to-end-of-buffer-line': function() {
return this.moveToEndOfBufferLine();
},
'editor:move-to-first-character-of-line': function() {
return this.moveToFirstCharacterOfLine();
},
Expand Down Expand Up @@ -383,9 +389,15 @@ module.exports = function({commandRegistry, commandInstaller, config, notificati
'editor:select-to-end-of-line': function() {
return this.selectToEndOfLine();
},
'editor:select-to-end-of-buffer-line': function() {
return this.selectToEndOfBufferLine();
},
'editor:select-to-beginning-of-line': function() {
return this.selectToBeginningOfLine();
},
'editor:select-to-beginning-of-buffer-line': function() {
return this.selectToBeginningOfBufferLine();
},
'editor:select-to-end-of-word': function() {
return this.selectToEndOfWord();
},
Expand Down Expand Up @@ -468,9 +480,15 @@ module.exports = function({commandRegistry, commandInstaller, config, notificati
'editor:delete-to-beginning-of-line': function() {
return this.deleteToBeginningOfLine();
},
'editor:delete-to-beginning-of-buffer-line': function() {
return this.deleteToBeginningOfBufferLine();
},
'editor:delete-to-end-of-line': function() {
return this.deleteToEndOfLine();
},
'editor:delete-to-end-of-buffer-line': function() {
return this.deleteToEndOfBufferLine();
},
'editor:delete-to-end-of-word': function() {
return this.deleteToEndOfWord();
},
Expand Down
118 changes: 102 additions & 16 deletions src/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,27 +308,49 @@ module.exports = class Selection {
}

// Public: Selects all the text from the current cursor position to the
// beginning of the line.
// beginning of the buffer line.
//
// Deprecated; prefer {::selectToBeginningOfBufferLine}.
selectToBeginningOfLine() {
this.modifySelection(() => this.cursor.moveToBeginningOfLine());
this.selectToBeginningOfBufferLine();
}

// Public: Selects all the text from the current cursor position to the
// beginning of the screen line.
selectToBeginningOfScreenLine() {
this.modifiySelection(() => this.cursor.moveToBeginningOfScreenLine());
}

// Public: Selects all the text from the current cursor position to the
// beginning of the buffer line.
selectToBeginningOfBufferLine() {
this.modifySelection(() => this.cursor.moveToBeginningOfBufferLine());
}

// Public: Selects all the text from the current cursor position to the first
// character of the line.
// non-whitespace character of the screen line.
selectToFirstCharacterOfLine() {
this.modifySelection(() => this.cursor.moveToFirstCharacterOfLine());
}

// Public: Selects all the text from the current cursor position to the end
// of the screen line.
//
// Deprecated; prefer {::selectToEndOfScreenLine}.
selectToEndOfLine() {
this.selectToEndOfScreenLine();
}

// Public: Selects all the text from the current cursor position to the end of
// the screen line.
selectToEndOfLine() {
selectToEndOfScreenLine() {
this.modifySelection(() => this.cursor.moveToEndOfScreenLine());
}

// Public: Selects all the text from the current cursor position to the end of
// the buffer line.
selectToEndOfBufferLine() {
this.modifySelection(() => this.cursor.moveToEndOfLine());
this.modifySelection(() => this.cursor.moveToEndOfBufferLine());
}

// Public: Selects all the text from the current cursor position to the
Expand Down Expand Up @@ -632,13 +654,24 @@ module.exports = class Selection {
this.deleteSelectedText(options);
}

// Public: Removes from the beginning of the line which the selection begins on
// all the way through to the end of the selection.
// Public: Removes from the beginning of the buffer line which the selection
// begins on all the way through to the end of the selection.
//
// * `options` (optional) {Object}
// * `bypassReadOnly` (optional) {Boolean} Must be `true` to modify text within a read-only editor. (default: false)
// Deprecated; prefer {::deleteToBeginningOfBufferLine}.
deleteToBeginningOfLine(options = {}) {
if (!this.ensureWritable('deleteToBeginningOfLine', options)) return;
return this.deleteToBeginningOfBufferLine(options);
}

// Public: Removes all text from the beginning of the buffer line which the
// selection begins on all the way through to the end of the selection. When
// the cursor is on the first column of the buffer line and the selection is
// empty, deletes the preceding newline character.
//
// * `options` (optional) {Object}
// * `bypassReadOnly` (optional) {Boolean} Must be `true` to modify text within a read-only editor. (default: false)
deleteToBeginningOfBufferLine(options = {}) {
if (!this.ensureWritable('deleteToBeginningOfBufferLine', options)) return;
if (this.isEmpty() && this.cursor.isAtBeginningOfLine()) {
this.selectLeft();
} else {
Expand All @@ -647,6 +680,23 @@ module.exports = class Selection {
this.deleteSelectedText(options);
}

// Public: Removes all text from the beginning of the screen line which the
// selection begins on all the way through to the end of the selection. When
// the cursor is on the first column of the buffer line and the selection is
// empty, deletes the preceding newline character.
//
// * `options` (optional) {Object}
// * `bypassReadOnly` (optional) {Boolean} Must be `true` to modify text within a read-only editor. (default: false)
deleteToBeginningOfScreenLine(options = {}) {
if (!this.ensureWritable('deleteToBeginningOfBufferLine', options)) return;
if (this.isEmpty()) {
this.selectLeft();
} else {
this.selectToBeginningOfLine();
}
this.deleteSelectedText(options);
}

// Public: Removes the selection or the next character after the start of the
// selection if the selection is empty.
//
Expand All @@ -659,20 +709,49 @@ module.exports = class Selection {
}

// Public: If the selection is empty, removes all text from the cursor to the
// end of the line. If the cursor is already at the end of the line, it
// removes the following newline. If the selection isn't empty, only deletes
// the contents of the selection.
// end of the screen line. If the cursor is already at the end of the screen
// line, deletes the following newline. If the selection isn't empty, only
// deletes the contents of the selection.
//
// Deprecated; prefer {::deleteToEndOfScreenLine}.
deleteToEndOfLine(options = {}) {
return this.deleteToEndOfScreenLine(options);
}

// Public: If the selection is empty, removes all text from the cursor to the
// end of the screen line. If the cursor is already at the end of the screen
// line, deletes the following newline. If the selection isn't empty, only
// deletes the contents of the selection.
//
// * `options` (optional) {Object}
// * `bypassReadOnly` (optional) {Boolean} Must be `true` to modify text within a read-only editor. (default: false)
deleteToEndOfLine(options = {}) {
if (!this.ensureWritable('deleteToEndOfLine', options)) return;
deleteToEndOfScreenLine(options = {}) {
if (!this.ensureWritable('deleteToEndOfScreenLine', options)) return;
if (this.isEmpty()) {
if (this.cursor.isAtEndOfLine()) {
this.delete(options);
return;
}
this.selectToEndOfLine();
this.selectToEndOfScreenLine();
}
this.deleteSelectedText(options);
}

// Public: If the selection is empty, removes all text from the cursor to the
// end of the buffer line. If the cursor is already at the end of the buffer
// line, deletes the following newline. If the selection isn't empty, only
// deletes the contents of the selection.
//
// * `options` (optional) {Object}
// * `bypassReadOnly` (optional) {Boolean} Must be `true` to modify text within a read-only editor. (default: false)
deleteToEndOfBufferLine(options = {}) {
if (!this.ensureWritable('deleteToEndOfBufferLine', options)) return;
if (this.isEmpty()) {
if (this.cursor.isAtEndOfLine()) {
this.delete(options);
return;
}
this.selectToEndOfBufferLine();
}
this.deleteSelectedText(options);
}
Expand Down Expand Up @@ -859,12 +938,19 @@ module.exports = class Selection {
});
}

// Public: Cuts the selection until the end of the screen line.
//
// Deprecated; prefer {::cutToEndOfScreenLine}.
cutToEndOfLine(maintainClipboard, options = {}) {
return this.cutToEndOfScreenLine(maintainClipboard, options);
}

// Public: Cuts the selection until the end of the screen line.
//
// * `maintainClipboard` {Boolean}
// * `options` (optional) {Object}
// * `bypassReadOnly` (optional) {Boolean} Must be `true` to modify text within a read-only editor. (default: false)
cutToEndOfLine(maintainClipboard, options = {}) {
cutToEndOfScreenLine(maintainClipboard, options = {}) {
if (!this.ensureWritable('cutToEndOfLine', options)) return;
if (this.isEmpty()) this.selectToEndOfLine();
return this.cut(maintainClipboard, false, options.bypassReadOnly);
Expand Down
Loading
Loading