This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 833
Better autocomplete #296
Merged
Merged
Better autocomplete #296
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b979a16
initial version of autocomplete
aviraldg 0df201c
Merge branch 'develop' into feature-autocomplete
aviraldg 4bc8ec3
room, user, ddg autocomplete providers (wip)
aviraldg 769b3f0
Merge branch 'develop' into feature-autocomplete
aviraldg b9d7743
Emoji provider, DDG working, style improvements
aviraldg 4af983e
Style changes and improvements in autocomplete
aviraldg 442291c
Merge branch 'develop' of github.com:matrix-org/matrix-react-sdk into…
aviraldg f6a76ed
Fuzzy matching in User and Room providers
aviraldg fb6eec0
Hide/show autocomplete based on selection state
aviraldg a74db3a
Get basic keyboard selection working
aviraldg cd928fe
Merge remote-tracking branch 'upstream/develop' into feature-autocomp…
aviraldg 8961c87
feat: Autocomplete selection wraparound
aviraldg cccc58b
feat: implement autocomplete replacement
aviraldg 30b7efd
fix: code cleanup, fix getCurrentCommand
aviraldg 73b726e
feat: import only flatMap from lodash
aviraldg b3d8292
feat: use canonical room alias for room completion
aviraldg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,45 @@ | ||
import React from 'react'; | ||
import AutocompleteProvider from './AutocompleteProvider'; | ||
import Q from 'q'; | ||
import Fuse from 'fuse.js'; | ||
import {TextualCompletion} from './Components'; | ||
|
||
const COMMANDS = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the longer term, we should try to get this information from the definitions of the commands in src/SlashCommands.js rather than duplicating the usage text here |
||
{ | ||
command: '/me', | ||
args: '<message>', | ||
description: 'Displays action' | ||
description: 'Displays action', | ||
}, | ||
{ | ||
command: '/ban', | ||
args: '<user-id> [reason]', | ||
description: 'Bans user with given id' | ||
description: 'Bans user with given id', | ||
}, | ||
{ | ||
command: '/deop' | ||
command: '/deop', | ||
args: '<user-id>', | ||
description: 'Deops user with given id', | ||
}, | ||
{ | ||
command: '/encrypt' | ||
}, | ||
{ | ||
command: '/invite' | ||
command: '/invite', | ||
args: '<user-id>', | ||
description: 'Invites user with given id to current room' | ||
}, | ||
{ | ||
command: '/join', | ||
args: '<room-alias>', | ||
description: 'Joins room with given alias' | ||
description: 'Joins room with given alias', | ||
}, | ||
{ | ||
command: '/kick', | ||
args: '<user-id> [reason]', | ||
description: 'Kicks user with given id' | ||
description: 'Kicks user with given id', | ||
}, | ||
{ | ||
command: '/nick', | ||
args: '<display-name>', | ||
description: 'Changes your display nickname' | ||
} | ||
description: 'Changes your display nickname', | ||
}, | ||
]; | ||
|
||
let COMMAND_RE = /(^\/\w*)/g; | ||
|
@@ -47,19 +50,23 @@ export default class CommandProvider extends AutocompleteProvider { | |
constructor() { | ||
super(COMMAND_RE); | ||
this.fuse = new Fuse(COMMANDS, { | ||
keys: ['command', 'args', 'description'] | ||
keys: ['command', 'args', 'description'], | ||
}); | ||
} | ||
|
||
getCompletions(query: string, selection: {start: number, end: number}) { | ||
let completions = []; | ||
const command = this.getCurrentCommand(query, selection); | ||
if(command) { | ||
let {command, range} = this.getCurrentCommand(query, selection); | ||
if (command) { | ||
completions = this.fuse.search(command[0]).map(result => { | ||
return { | ||
title: result.command, | ||
subtitle: result.args, | ||
description: result.description | ||
completion: result.command + ' ', | ||
component: (<TextualCompletion | ||
title={result.command} | ||
subtitle={result.args} | ||
description={result.description} | ||
/>), | ||
range, | ||
}; | ||
}); | ||
} | ||
|
@@ -71,7 +78,7 @@ export default class CommandProvider extends AutocompleteProvider { | |
} | ||
|
||
static getInstance(): CommandProvider { | ||
if(instance == null) | ||
if (instance == null) | ||
instance = new CommandProvider(); | ||
|
||
return instance; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
export function TextualCompletion(props: { | ||
import React from 'react'; | ||
|
||
export function TextualCompletion({ | ||
title, | ||
subtitle, | ||
description, | ||
}: { | ||
title: ?string, | ||
subtitle: ?string, | ||
description: ?string | ||
}) { | ||
return ( | ||
<div className="mx_Autocomplete_Completion"> | ||
<span>{completion.title}</span> | ||
<em>{completion.subtitle}</em> | ||
<span style={{color: 'gray', float: 'right'}}>{completion.description}</span> | ||
<span>{title}</span> | ||
<em>{subtitle}</em> | ||
<span style={{color: 'gray', float: 'right'}}>{description}</span> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need to be added to
window
? And why the different one insrc/autocomplete/EmojiProvider.js
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While putting it on window looks like debugging code, this regexp is different (should be) different from the one in EmojiProvider since this handles rendering of unicode emoji in the message composer (a feature which is disabled for now due to bugs in Draft.js)