Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark autocomplete #377

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/assets/ts/components/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ class RowComponent extends React.Component<RowProps, {}> {
linksStyle: getStyles(session.clientStore, ['theme-link']),
accentStyle: getStyles(session.clientStore, ['theme-text-accent']),
cursorBetween: this.props.cursorBetween,
sessionApplyHook: session.applyHook.bind(session),
};

const hooksInfo = {
path, pluginData: this.props.cached.pluginData,
has_cursor, has_highlight
has_cursor, has_highlight, lineData
};

lineoptions.lineHook = PartialUnfolder.trivial<Token, React.ReactNode>();
Expand Down
8 changes: 7 additions & 1 deletion src/assets/ts/components/line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type LineProps = {
wordHook?: PartialUnfolder<Token, React.ReactNode>;
onCharClick?: ((col: Col, e: Event) => void) | undefined;
cursorBetween?: boolean;
sessionApplyHook?: (event: string, obj: any, info: any) => Array<React.ReactNode>,
};

// NOTE: hacky! we don't include .:/?= since urls contain it
Expand Down Expand Up @@ -106,6 +107,10 @@ export default class LineComponent extends React.Component<LineProps, {}> {
onClick = this.props.onCharClick.bind(this, column);
}
}
let children = null;
if (this.props.sessionApplyHook) {
children = this.props.sessionApplyHook('renderCharChildren', [], { lineData, column, cursors });
}
const divType = char_info.renderOptions.divType || 'span';
emit(
React.createElement(
Expand All @@ -118,7 +123,8 @@ export default class LineComponent extends React.Component<LineProps, {}> {
href: href,
target: target
} as React.DOMAttributes<any>,
token.text[i] as React.ReactNode
token.text[i] as React.ReactNode,
children
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/assets/ts/cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class Cursor extends EventEmitter {
}

private async _setCol(col: Col) {
await this.emitAsync('colChange', this.col, col);
await this.session.applyHookAsync('colChange', {}, {oldCol: this.col, newCol: col});
this.col = col;
}

Expand Down
2 changes: 2 additions & 0 deletions src/assets/ts/definitions/basics.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isLink } from '../utils/text';
import keyDefinitions, { Action, ActionContext, SequenceAction } from '../keyDefinitions';
import _, { stubObject } from 'lodash';

keyDefinitions.registerAction(new Action(
'move-cursor-normal',
Expand Down Expand Up @@ -28,6 +29,7 @@ keyDefinitions.registerAction(new Action(
if (motion == null) {
throw new Error('Motion command was not passed a motion');
}
context.keyStream.save();
await motion(session.cursor, {pastEnd: true});
},
{ acceptsMotion: true },
Expand Down
7 changes: 5 additions & 2 deletions src/assets/ts/modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const deregisterMode = function(mode: ModeMetadata) {
delete MODES[mode.name];
};

const transform_insert_key = function(key: Key) {
export const transform_insert_key = function(key: Key) {
if (key === 'shift+enter') {
key = '\n';
} else if (key === 'space' || key === 'shift+space') {
Expand Down Expand Up @@ -147,7 +147,7 @@ registerMode({
],
});

const nonSavingInsertActions: {[key: string]: boolean} = {
export const nonSavingInsertActions: {[key: string]: boolean} = {
'delete-char-before': true,
'delete-char-after': true,
};
Expand Down Expand Up @@ -183,6 +183,9 @@ registerMode({
session.save();
}
},
async enter(session: Session) {
await session.cursor.setCol(session.cursor.col); // just to call colChange event
},
async exit(session: Session) {
await session.cursor.left();
// unlike other modes, esc in insert mode keeps changes
Expand Down
Loading