Skip to content

Commit 8dad4da

Browse files
committed
完善debug信息
1 parent 4c75e2a commit 8dad4da

File tree

5 files changed

+65
-23
lines changed

5 files changed

+65
-23
lines changed

src/components/layout/index.tsx

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,8 @@ function LayoutComponent(props: {session: Session, config: Config, pluginManager
7878
const [curDocInfo, setCurDocInfo] = useState({});
7979
const [editor, setEditor] = useState<IDomEditor | null>(null);
8080
const [html, setHtml] = useState('<p>');
81-
const [debugSelecting, setDebugSelecting] = useState(props.session.selecting);
8281
const [xml, setXml] = useState<string | undefined>();
8382
const [vd, setVd] = React.useState<Vditor>();
84-
useEffect(() => {
85-
console.log('found session change');
86-
setDebugSelecting(props.session.selecting);
87-
}, [props.session.selecting, props.session.hoverRow]);
8883
useEffect(() => {
8984
setCurPage(location.pathname.split('/')[1] || 'note');
9085
}, [location]);
@@ -403,24 +398,6 @@ function LayoutComponent(props: {session: Session, config: Config, pluginManager
403398
}
404399
}
405400
}}/>
406-
{
407-
props.session.debugMode &&
408-
<div style={{display: 'flex'}}>
409-
{/*<div>*/}
410-
{/* <span>hover: {props.session.hoverRow?.row}</span>*/}
411-
{/* <span>anchor: {props.session.getAnchor()?.row}</span>*/}
412-
{/* <span>cursor: {props.session.cursor.row}</span>*/}
413-
{/* <span>selectInlinePath: {props.session.selectInlinePath?.row}</span>*/}
414-
{/*</div>*/}
415-
<div>
416-
<span>selecting: {debugSelecting ? 'true' : 'false'}</span>
417-
<span>dragging: {props.session.dragging}</span>
418-
<span>selectPopoverOpen: {props.session.selectPopoverOpen}</span>
419-
<span>selectMousePressing: {props.session.selectMousePressing}</span>
420-
<span>stopMonitor: {props.session.stopMonitor}</span>
421-
</div>
422-
</div>
423-
}
424401
{
425402
curPage === 'note' &&
426403
<Button onClick={() => {

src/components/session/debugger.tsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import * as React from 'react';
2+
import {Session} from '../../share';
3+
type DebuggerProps = {
4+
session: Session;
5+
};
6+
7+
export class SessionDebugger extends React.Component<DebuggerProps, {}> {
8+
9+
public shouldComponentUpdate(nextProps: DebuggerProps) {
10+
return true;
11+
}
12+
13+
public render() {
14+
return (
15+
<div style={{position: 'fixed', top: '0px', left: '500px'}}>
16+
{
17+
this.props.session.stopMonitor &&
18+
<div>
19+
Stopping keydown monitor
20+
</div>
21+
}
22+
{
23+
this.props.session.hoverRow &&
24+
<div>
25+
Hovering {this.props.session.hoverRow.row}
26+
</div>
27+
}
28+
{
29+
this.props.session.selecting &&
30+
<div>
31+
<div>
32+
Selecting anchor {this.props.session.getAnchor()?.row} cursor {this.props.session.cursor.row}
33+
</div>
34+
{
35+
this.props.session.selectInlinePath &&
36+
<div>
37+
Inline startCol {this.props.session.getAnchor()?.col} endCol {this.props.session.cursor.col}
38+
</div>
39+
}
40+
{
41+
this.props.session.selectPopoverOpen &&
42+
<div>
43+
Popover Open
44+
</div>
45+
}
46+
</div>
47+
}
48+
</div>
49+
);
50+
}
51+
}

src/share/components/Block/block.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ export default class BlockComponent extends React.Component<BlockProps, {}> {
260260
if (nextProps.filteredRows !== this.props.filteredRows) {
261261
return true;
262262
}
263+
if (this.props.session.debugMode) {
264+
return true;
265+
}
263266
if (nextProps.session.lastHoverRow?.getAncestry().includes(nextProps.path.row) ||
264267
nextProps.session.hoverRow?.getAncestry().includes(nextProps.path.row)) {
265268
return true;

src/share/components/Session/Session.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Col } from '../../ts/types';
1111
import Path from '../../ts/path';
1212
import $ from 'jquery';
1313
import { CursorsInfoTree } from '../../ts/cursor';
14+
import {SessionDebugger} from '../../../components/session/debugger';
1415

1516
// TODO: move mode-specific logic into mode render functions
1617

@@ -316,6 +317,10 @@ export default class SessionComponent extends React.Component<Props, State> {
316317
this.props.session.setHoverRow(null, 'mouse leave');
317318
}}
318319
>
320+
{
321+
this.props.session.debugMode &&
322+
<SessionDebugger session={this.props.session}/>
323+
}
319324
<BlockComponent
320325
iconNoTopLevel='fa-circle'
321326
iconDirFold='fa-circle'

src/share/ts/session.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ export default class Session extends EventEmitter {
185185
public startKeyMonitor() {
186186
// console.log('startKeyMonitor');
187187
this.stopMonitor = this.clientStore.getClientSetting('curView') === 'discovery';
188+
if (this.debugMode) {
189+
this.emit('updateInner')
190+
}
188191
}
189192

190193
public markSelecting(selecting: boolean, callsite: string) {
@@ -195,6 +198,9 @@ export default class Session extends EventEmitter {
195198
public stopKeyMonitor(caller: string) {
196199
// console.log('stopKeyMonitor from:', caller);
197200
this.stopMonitor = true;
201+
if (this.debugMode) {
202+
this.emit('updateInner')
203+
}
198204
}
199205

200206
public applySearch(filterContent: string) {

0 commit comments

Comments
 (0)