Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 79d37aa

Browse files
author
Alun Turner
committed
improve comments
1 parent 6e62bb1 commit 79d37aa

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/components/views/rooms/wysiwyg_composer/hooks/useSuggestion.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ export function useSuggestion(
8383
}
8484

8585
/**
86-
* Replaces the relevant part of the editor text with the replacement mention after it is selected
87-
* from the autocomplete.
86+
* Replaces the relevant part of the editor text with a link representing a mention after it
87+
* is selected from the autocomplete.
8888
*
89-
* @param href - the href to be attached for the mention
90-
* @param displayName - the text to display for the mention
91-
* @param attributes - additional attributes to apply to the mention before adding to the editor
89+
* @param href - the href that the inserted link will use
90+
* @param displayName - the text content of the link
91+
* @param attributes - additional attributes to add to the link, can include data-* attributes
9292
* @param suggestion - representation of the part of the DOM that will be replaced
9393
* @param setSuggestion - setter function to set the suggestion state
9494
* @param setText - setter function to set the content of the composer
@@ -111,12 +111,12 @@ export function processMention(
111111
const textBeforeReplacement = node.textContent?.slice(0, suggestion.startOffset) ?? "";
112112
const textAfterReplacement = node.textContent?.slice(suggestion.endOffset) ?? "";
113113

114-
// do this in markdown style for now
114+
// TODO replace this markdown style text insertion with a pill representation
115115
const newText = `[${displayName}](<${href}>) `;
116116
const newCursorOffset = textBeforeReplacement.length + newText.length;
117117
const newContent = textBeforeReplacement + newText + textAfterReplacement;
118118

119-
// insert the new text, move the cursor, set the text state, clear the suggestion
119+
// insert the new text, move the cursor, set the text state, clear the suggestion state
120120
node.textContent = newContent;
121121
document.getSelection()?.setBaseAndExtent(node, newCursorOffset, node, newCursorOffset);
122122
setText(newContent);
@@ -245,8 +245,8 @@ export function processSelectionChange(
245245
return;
246246
}
247247

248-
// here we have established that both anchor and focus nodes in the selection are
249-
// the same node, so rename to `currentNode` for later use
248+
// here we have established that we have a cursor and both anchor and focus nodes in the selection
249+
// are the same node, so rename to `currentNode` and `currentOffset` for subsequent use
250250
const { anchorNode: currentNode, anchorOffset: currentOffset } = selection;
251251

252252
// first check is that the text node is the first text node of the editor, as adding paragraphs can result
@@ -258,7 +258,7 @@ export function processSelectionChange(
258258

259259
const mentionOrCommand = findMentionOrCommand(currentNode.textContent, currentOffset);
260260

261-
// if we don't have any mentionsOrCommands, return, clearing the suggeston state if it is non-null
261+
// if we don't have any mentionsOrCommands, return, clearing the suggestion state
262262
if (mentionOrCommand === null) {
263263
setSuggestion(null);
264264
return;
@@ -284,7 +284,8 @@ export function processSelectionChange(
284284

285285
/**
286286
* Given a string that represents a suggestion in the composer, return an object that represents
287-
* that text as a `MappedSuggestion`
287+
* that text as a `MappedSuggestion`.
288+
*
288289
* @param suggestionText - string that could be a mention of a command type suggestion
289290
* @returns an object representing the `MappedSuggestion` from that string
290291
*/

0 commit comments

Comments
 (0)