mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-24 04:00:59 +01:00
editor: infer dir from parent when adding heading
This commit is contained in:
committed by
Abdullah Atta
parent
19faaea10e
commit
578fb72ddc
@@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { textblockTypeInputRule } from "@tiptap/core";
|
||||
import { Heading as TiptapHeading } from "@tiptap/extension-heading";
|
||||
|
||||
export const Heading = TiptapHeading.extend({
|
||||
@@ -40,5 +41,31 @@ export const Heading = TiptapHeading.extend({
|
||||
});
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
addKeyboardShortcuts() {
|
||||
return this.options.levels.reduce(
|
||||
(items, level) => ({
|
||||
...items,
|
||||
...{
|
||||
[`Mod-Alt-${level}`]: () => this.editor.commands.setHeading({ level })
|
||||
}
|
||||
}),
|
||||
{}
|
||||
);
|
||||
},
|
||||
|
||||
addInputRules() {
|
||||
return this.options.levels.map((level) => {
|
||||
return textblockTypeInputRule({
|
||||
find: new RegExp(`^(#{1,${level}})\\s$`),
|
||||
type: this.type,
|
||||
getAttributes: () => {
|
||||
const { textAlign, textDirection } =
|
||||
this.editor.state.selection.$from.parent.attrs;
|
||||
return { level, textAlign, textDirection };
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user