Created
February 1, 2019 21:41
-
-
Save Tug/e9e64412dd2d87e205fecbbf8db98540 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
diff --git a/packages/rich-text/src/apply-format.native.js b/packages/rich-text/src/apply-format.native.js | |
index 9c5a4749a..2d2fa9829 100644 | |
--- a/packages/rich-text/src/apply-format.native.js | |
+++ b/packages/rich-text/src/apply-format.native.js | |
@@ -35,7 +35,7 @@ export function applyFormat( | |
// The selection is collpased, insert a placeholder with the format so new input appears | |
// with the format applied. | |
if ( startIndex === endIndex ) { | |
- const previousFormats = currentFormats[ startIndex - 1 ] || []; | |
+ const previousFormats = currentFormats[ startIndex > 0 ? startIndex - 1 : 0 ] || []; | |
const placeholderFormats = formatPlaceholder && formatPlaceholder.index === start && formatPlaceholder.formats; | |
// Follow the same logic as in getActiveFormat: placeholderFormats has priority over previousFormats | |
const activeFormats = ( placeholderFormats ? placeholderFormats : previousFormats ) || []; | |
diff --git a/packages/rich-text/src/get-active-format.native.js b/packages/rich-text/src/get-active-format.native.js | |
index 7ff34aa7f..66c9f061d 100644 | |
--- a/packages/rich-text/src/get-active-format.native.js | |
+++ b/packages/rich-text/src/get-active-format.native.js | |
@@ -31,7 +31,7 @@ export function getActiveFormat( { formats, formatPlaceholder, start, end }, for | |
} | |
// otherwise get the previous character format | |
- const previousLetterFormat = find( formats[ start - 1 ], { type: formatType } ); | |
+ const previousLetterFormat = find( formats[ start > 0 ? start - 1 : 0 ], { type: formatType } ); | |
if ( previousLetterFormat ) { | |
return previousLetterFormat; | |
diff --git a/packages/rich-text/src/remove-format.native.js b/packages/rich-text/src/remove-format.native.js | |
index b6213f813..b155796da 100644 | |
--- a/packages/rich-text/src/remove-format.native.js | |
+++ b/packages/rich-text/src/remove-format.native.js | |
@@ -40,7 +40,7 @@ export function removeFormat( | |
formats: cloneDeep( placeholderFormats.filter( ( { type } ) => type !== formatType ) ), | |
}; | |
} else if ( ! formatPlaceholder ) { | |
- const previousFormat = ( start > 0 ? formats[ start - 1 ] : formats[ 0 ] ) || []; | |
+ const previousFormat = formats[ start > 0 ? start - 1 : 0 ] || []; | |
newFormatPlaceholder = { | |
index: start, | |
formats: cloneDeep( previousFormat.filter( ( { type } ) => type !== formatType ) ), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment