-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: make shift+enter work in lists (#13546)
* WIP: make shift+enter work in lists * Merge similar logic * Add e2e tests
- Loading branch information
1 parent
bee0424
commit 3788066
Showing
5 changed files
with
73 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
|
||
import { insert } from './insert'; | ||
import { LINE_SEPARATOR } from './special-characters'; | ||
|
||
/** | ||
* Inserts a line break at the given or selected position. Inserts two line | ||
* breaks if at the end of a line. | ||
* | ||
* @param {Object} value Value to modify. | ||
* | ||
* @return {Object} The value with the line break(s) inserted. | ||
*/ | ||
export function insertLineBreak( value ) { | ||
const { text, end } = value; | ||
const length = text.length; | ||
|
||
let toInsert = '\n'; | ||
|
||
// If the caret is at the end of the text, and there is no | ||
// trailing line break or no text at all, we have to insert two | ||
// line breaks in order to create a new line visually and place | ||
// the caret there. | ||
if ( | ||
( end === length || text[ end ] === LINE_SEPARATOR ) && | ||
( text[ end - 1 ] !== '\n' || length === 0 ) | ||
) { | ||
toInsert = '\n\n'; | ||
} | ||
|
||
return insert( value, toInsert ); | ||
} |