Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid committed Sep 21, 2023
1 parent ad8619e commit 43adfe9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/libs/SelectionScraper/index.native.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import GetCurrentSelection from './types';

// This is a no-op function for native devices because they wouldn't be able to support Selection API like a website.
const getCurrentSelection: GetCurrentSelection = () => '';

export default {
// This is a no-op function for native devices because they wouldn't be able to support Selection API like a website.
getCurrentSelection: () => '',
getCurrentSelection,
};
7 changes: 4 additions & 3 deletions src/libs/SelectionScraper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {parseDocument} from 'htmlparser2';
import Str from 'expensify-common/lib/str';
import {DataNode, Element, Node} from 'domhandler';
import CONST from '../../CONST';
import GetCurrentSelection from './types';

const elementsWillBeSkipped = ['html', 'body'];
const tagAttribute = 'data-testid';
Expand Down Expand Up @@ -44,7 +45,7 @@ const getHTMLOfSelection = (): string => {

// If clonedSelection has no text content this data has no meaning to us.
if (clonedSelection.textContent) {
let parent;
let parent: globalThis.Element | null = null;
let child = clonedSelection;

// If selection starts and ends within same text node we use its parentNode. This is because we can't
Expand Down Expand Up @@ -101,7 +102,7 @@ const replaceNodes = (dom: Node, isChildOfEditorElement: boolean): Node => {
const domElement = dom as Element;
let domName = domElement.name;
let domChildren: Node[] = [];
const domAttribs = {} as Element['attribs'];
const domAttribs: Element['attribs'] = {};
let data = '';

// Encoding HTML chars '< >' in the text, because any HTML will be removed in stripHTML method.
Expand Down Expand Up @@ -148,7 +149,7 @@ const replaceNodes = (dom: Node, isChildOfEditorElement: boolean): Node => {
/**
* Resolves the current selection to values and produces clean HTML.
*/
const getCurrentSelection = (): string => {
const getCurrentSelection: GetCurrentSelection = () => {
const domRepresentation = parseDocument(getHTMLOfSelection());
domRepresentation.children = domRepresentation.children.map((item) => replaceNodes(item, false));

Expand Down
3 changes: 3 additions & 0 deletions src/libs/SelectionScraper/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type GetCurrentSelection = () => string;

export default GetCurrentSelection;

0 comments on commit 43adfe9

Please sign in to comment.