mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-05-18 05:05:36 +02:00
editor: fix TouchEvent is not defined when resizing columns
This commit is contained in:
@@ -1,3 +1,22 @@
|
||||
/*
|
||||
This file is part of the Notesnook project (https://notesnook.com/)
|
||||
|
||||
Copyright (C) 2023 Streetwriters (Private) Limited
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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 { Attrs, Node as ProsemirrorNode } from "prosemirror-model";
|
||||
import { EditorState, Plugin, PluginKey, Transaction } from "prosemirror-state";
|
||||
import {
|
||||
@@ -9,7 +28,7 @@ import {
|
||||
import { tableNodeTypes } from "./schema.js";
|
||||
import { TableMap } from "./tablemap.js";
|
||||
import { TableView, updateColumnsOnResize } from "./tableview.js";
|
||||
import { cellAround, CellAttrs, getClientX } from "./util.js";
|
||||
import { cellAround, CellAttrs, getClientX, isTouchEvent } from "./util.js";
|
||||
|
||||
/**
|
||||
* @public
|
||||
@@ -192,8 +211,7 @@ function handleMouseDown(
|
||||
|
||||
const pluginState = columnResizingPluginKey.getState(view.state);
|
||||
if (pluginState?.dragging) {
|
||||
if (event instanceof TouchEvent)
|
||||
(view as any).domObserver.connectSelection();
|
||||
if (isTouchEvent(event)) (view as any).domObserver.connectSelection();
|
||||
updateColumnWidth(
|
||||
view,
|
||||
activeHandle,
|
||||
@@ -224,8 +242,7 @@ function handleMouseDown(
|
||||
win.addEventListener("touchcancel", finish);
|
||||
win.addEventListener("touchmove", move);
|
||||
event.preventDefault();
|
||||
if (event instanceof TouchEvent)
|
||||
(view as any).domObserver.disconnectSelection();
|
||||
if (isTouchEvent(event)) (view as any).domObserver.disconnectSelection();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,21 @@
|
||||
// This file defines a number of helpers for wiring up user input to
|
||||
// table-related functionality.
|
||||
/*
|
||||
This file is part of the Notesnook project (https://notesnook.com/)
|
||||
|
||||
Copyright (C) 2023 Streetwriters (Private) Limited
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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 { keydownHandler } from "prosemirror-keymap";
|
||||
import { Fragment, ResolvedPos, Slice } from "prosemirror-model";
|
||||
@@ -23,6 +39,7 @@ import {
|
||||
getClientY,
|
||||
inSameTable,
|
||||
isInTable,
|
||||
isTouchEvent,
|
||||
nextCell,
|
||||
selectionCell,
|
||||
tableEditingKey
|
||||
@@ -313,7 +330,3 @@ function cellUnderMouse(
|
||||
if (!mousePos) return null;
|
||||
return mousePos ? cellAround(view.state.doc.resolve(mousePos.pos)) : null;
|
||||
}
|
||||
|
||||
function isTouchEvent(event: Event): event is TouchEvent {
|
||||
return "TouchEvent" in window && event instanceof TouchEvent;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,21 @@
|
||||
// Various helper function for working with tables
|
||||
/*
|
||||
This file is part of the Notesnook project (https://notesnook.com/)
|
||||
|
||||
Copyright (C) 2023 Streetwriters (Private) Limited
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
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 { EditorState, NodeSelection, PluginKey } from "prosemirror-state";
|
||||
|
||||
@@ -216,3 +233,7 @@ export function getClientY(event: MouseEvent | TouchEvent): number | null {
|
||||
? event.changedTouches[0].clientY
|
||||
: null;
|
||||
}
|
||||
|
||||
export function isTouchEvent(event: Event): event is TouchEvent {
|
||||
return "TouchEvent" in window && event instanceof TouchEvent;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user