From 795669bdb79e5fbfa3044fa11fb061d4b6daa98a Mon Sep 17 00:00:00 2001 From: rebornix Date: Fri, 30 Jul 2021 13:17:53 -0700 Subject: [PATCH 1/2] Remove look behind for Safari. --- src/actions/languages/python/motion.ts | 13 ++++++++++++- src/state/searchState.ts | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/actions/languages/python/motion.ts b/src/actions/languages/python/motion.ts index 0d131102fb9..74df6c3dc60 100755 --- a/src/actions/languages/python/motion.ts +++ b/src/actions/languages/python/motion.ts @@ -19,6 +19,15 @@ interface StructureElement { end: Position; } +// Older browsers don't support lookbehind - in this case, use an inferior regex rather than crashing +let supportsLookbehind = true; +try { + // tslint:disable-next-line + new RegExp('(?<=x)'); +} catch { + supportsLookbehind = false; +} + /* * Utility class used to parse the lines in the document and * determine class and function boundaries @@ -31,7 +40,9 @@ export class PythonDocument { structure: StructureElement[]; static readonly reOnlyWhitespace = /\S/; - static readonly reLastNonWhiteSpaceCharacter = /(?<=\S)\s*$/; + static readonly reLastNonWhiteSpaceCharacter = supportsLookbehind + ? new RegExp('/(?<=\\S)\\s*$/') + : /(\S)\s*$/; static readonly reDefOrClass = /^\s*(def|class) /; constructor(document: TextDocument) { diff --git a/src/state/searchState.ts b/src/state/searchState.ts index 5624eecaae8..3ba64f62a43 100644 --- a/src/state/searchState.ts +++ b/src/state/searchState.ts @@ -27,7 +27,9 @@ export class SearchState { private static readonly specialCharactersRegex = /[\-\[\]{}()*+?.,\\\^$|#\s]/g; // c or C with an odd number of preceding \'s triggers "case override" - private static readonly caseOverrideRegex = /(?<=(?:^|[^\\])(?:\\\\)*)\\[Cc]/g; + private static readonly caseOverrideRegex = supportsLookbehind + ? new RegExp('(?<=(?:^|[^\\\\])(?:\\\\\\\\)*)\\\\[Cc]', 'g') + : /\\[Cc]/g; private static readonly notEscapedSlashRegex = supportsLookbehind ? new RegExp('(?<=[^\\\\])\\/', 'g') : /\//g; From 3535648f7e073b2e753f9ac021dc6972cddc77ce Mon Sep 17 00:00:00 2001 From: rebornix Date: Tue, 10 Aug 2021 14:17:57 -0700 Subject: [PATCH 2/2] fix python motion regex. --- src/actions/languages/python/motion.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/languages/python/motion.ts b/src/actions/languages/python/motion.ts index 74df6c3dc60..52f918da293 100755 --- a/src/actions/languages/python/motion.ts +++ b/src/actions/languages/python/motion.ts @@ -41,7 +41,7 @@ export class PythonDocument { static readonly reOnlyWhitespace = /\S/; static readonly reLastNonWhiteSpaceCharacter = supportsLookbehind - ? new RegExp('/(?<=\\S)\\s*$/') + ? new RegExp('(?<=\\S)\\s*$') : /(\S)\s*$/; static readonly reDefOrClass = /^\s*(def|class) /;