From 2959ace822426d014fe3325f0abef8ca797268f4 Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Fri, 5 Feb 2021 12:19:17 +0100 Subject: [PATCH] refactoring --- packages/extension-focus/src/focus.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/extension-focus/src/focus.ts b/packages/extension-focus/src/focus.ts index e24c26f2..57499760 100644 --- a/packages/extension-focus/src/focus.ts +++ b/packages/extension-focus/src/focus.ts @@ -5,7 +5,8 @@ import { DecorationSet, Decoration } from 'prosemirror-view' export interface FocusOptions { className: string, start: 'deep' | 'shallow', - levels: 'all' | number, + exact: boolean, + // levels: 'all' | number, } export const FocusClasses = Extension.create({ @@ -14,7 +15,8 @@ export const FocusClasses = Extension.create({ defaultOptions: { className: 'has-focus', start: 'deep', - levels: 'all', + exact: false, + // levels: 'all', }, addProseMirrorPlugins() { @@ -62,10 +64,15 @@ export const FocusClasses = Extension.create({ currentLevel += 1 - const outOfScope = typeof this.options.levels === 'number' + // const outOfScope = typeof this.options.levels === 'number' + // && ( + // (this.options.start === 'deep' && maxLevels - currentLevel > this.options.levels) + // || (this.options.start === 'shallow' && currentLevel > this.options.levels) + // ) + const outOfScope = this.options.exact && ( - (this.options.start === 'deep' && maxLevels - currentLevel > this.options.levels) - || (this.options.start === 'shallow' && currentLevel > this.options.levels) + (this.options.start === 'deep' && maxLevels - currentLevel !== 0) + || (this.options.start === 'shallow' && currentLevel > 1) ) if (outOfScope) {