Skip to content

Commit

Permalink
fix focus
Browse files Browse the repository at this point in the history
  • Loading branch information
ra3orblade committed Oct 4, 2024
1 parent ce013b2 commit 5a548fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
19 changes: 6 additions & 13 deletions src/ts/component/editor/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,20 +335,12 @@ const EditorPage = observer(class EditorPage extends React.Component<Props, Stat
focusInit () {
const { rootId, isPopup } = this.props;
const isReadonly = this.isReadonly();
const storage = Storage.getFocus(rootId);

if (isReadonly) {
return;
};

const title = S.Block.getLeaf(rootId, J.Constant.blockId.title);
if (title && !title.getLength()) {
focus.set(title.id, { from: 0, to: 0 });
focus.apply();
};

/*
const storage = Storage.getFocus(rootId);
let block = null;
let from = 0;
let to = 0;
Expand All @@ -358,10 +350,12 @@ const EditorPage = observer(class EditorPage extends React.Component<Props, Stat
from = storage.range.from;
to = storage.range.to;
};

if (!block) {
block = S.Block.getFirstBlock(rootId, 1, it => it.isText() && !it.getLength());
from = 0;
to = 0;
block = S.Block.getLeaf(rootId, J.Constant.blockId.title);
if (block && block.getLength()) {
block = null;
};
};

if (!block) {
Expand All @@ -372,7 +366,6 @@ const EditorPage = observer(class EditorPage extends React.Component<Props, Stat
focus.apply();

window.setTimeout(() => focus.scroll(isPopup, block.id), 10);
*/
};

unbind () {
Expand Down
4 changes: 2 additions & 2 deletions src/ts/lib/focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ class Focus {
const ch = container.height();
const no = node.offset().top;
const hh = J.Size.header;
const o = J.Size.lastBlock + ch / 2 + hh;
const o = J.Size.lastBlock + hh;
const st = container.scrollTop();
const y = isPopup ? (no - container.offset().top + st) : no;

if ((y >= st) && (y <= st + ch - o)) {
if ((y >= st) && (y <= st + ch / 2 - o)) {
return;
};

Expand Down

0 comments on commit 5a548fb

Please sign in to comment.