-
Notifications
You must be signed in to change notification settings - Fork 571
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix folder mentions in autocomplete input
- Loading branch information
1 parent
2fe8d79
commit 82d4ce3
Showing
4 changed files
with
43 additions
and
47 deletions.
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
32 changes: 32 additions & 0 deletions
32
client/src/Project/CurrentTabContent/ChatTab/Input/utils.ts
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,9 +1,41 @@ | ||
import OrderedMap from 'orderedmap'; | ||
import { type NodeSpec } from 'prosemirror-model'; | ||
import { | ||
InputEditorContent, | ||
ParsedQueryTypeEnum, | ||
} from '../../../../types/general'; | ||
import { mentionNode } from './nodes'; | ||
|
||
export function addMentionNodes(nodes: OrderedMap<NodeSpec>) { | ||
return nodes.append({ | ||
mention: mentionNode, | ||
}); | ||
} | ||
|
||
export const mapEditorContentToInputValue = ( | ||
inputState: InputEditorContent[], | ||
) => { | ||
const getType = (type: string) => (type === 'lang' ? 'lang' : 'path'); | ||
const newValue = inputState | ||
.map((s) => | ||
s.type === 'mention' | ||
? `${getType(s.attrs.type)}:${s.attrs.id}` | ||
: s.text.replace(new RegExp(String.fromCharCode(160), 'g'), ' '), | ||
) | ||
.join(''); | ||
const newValueParsed = inputState.map((s) => | ||
s.type === 'mention' | ||
? { | ||
type: | ||
s.attrs.type === 'lang' | ||
? ParsedQueryTypeEnum.LANG | ||
: ParsedQueryTypeEnum.PATH, | ||
text: s.attrs.id, | ||
} | ||
: { type: ParsedQueryTypeEnum.TEXT, text: s.text }, | ||
); | ||
return { | ||
plain: newValue, | ||
parsed: newValueParsed, | ||
}; | ||
}; |