Skip to content

Commit

Permalink
type: Modify types.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Sep 8, 2021
1 parent dbd8298 commit 0166a3c
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { codePreview, codeEdit, codeLive } from './preview';
import { fullscreen } from './fullscreen';
import { image } from './image';
import { strikethrough } from './strikeThrough';
import insertText from '../utils/InsertTextAtPosition';
import { insertTextAtPosition } from '../utils/InsertTextAtPosition';
import { ContextStore, ExecuteCommandState } from '../Context';

export interface CommandOrchestrator {
Expand Down Expand Up @@ -116,7 +116,7 @@ class TextAreaTextApi {
* @param text Text that should replace the current selection
*/
replaceSelection(text: string): TextState {
insertText(this.textArea, text);
insertTextAtPosition(this.textArea, text);
return getStateFromTextArea(this.textArea);
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/TextArea/handleKeyDown.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import insertText from '../../utils/InsertTextAtPosition';
import { insertTextAtPosition } from '../../utils';
import { TextAreaTextApi } from '../../commands';
import { insertBeforeEachLine } from '../../commands/list';

Expand Down Expand Up @@ -63,7 +63,7 @@ export default function handleKeyDown(
end: newStarNum + oldSelectText.length + endTabSize,
});
} else {
return insertText(target, space);
return insertTextAtPosition(target, space);
}
} else if (
e.code &&
Expand All @@ -81,6 +81,6 @@ export default function handleKeyDown(
if (/^\d+.\s/.test(currentLineStr)) {
startStr = `\n${parseInt(currentLineStr) + 1}. `;
}
return insertText(target, startStr);
return insertTextAtPosition(target, startStr);
}
}
2 changes: 1 addition & 1 deletion src/utils/InsertTextAtPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function canManipulateViaTextNodes(input: HTMLTextAreaElement | HTMLInputElement
* @param {string} text
* @returns {void}
*/
export default function insertTextAtPosition(input: HTMLTextAreaElement | HTMLInputElement, text: string) {
export function insertTextAtPosition(input: HTMLTextAreaElement | HTMLInputElement, text: string) {
// Most of the used APIs only work with the field selected
input.focus();

Expand Down
2 changes: 1 addition & 1 deletion src/utils/getSurroundingWord.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TextRange } from '../commands';

export default function getSurroundingWord(text: string, position: number): TextRange {
export function getSurroundingWord(text: string, position: number): TextRange {
if (!text) throw Error("Argument 'text' should be truthy");

const isWordDelimiter = (c: string) => c === ' ' || c.charCodeAt(0) === 10;
Expand Down
4 changes: 4 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export * from './getSurroundingWord';
export * from './InsertTextAtPosition';
export * from './markdownUtils';

export interface IProps {
prefixCls?: string;
className?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/markdownUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TextRange } from '../commands';
import getSurroundingWord from './getSurroundingWord';
import { getSurroundingWord } from './getSurroundingWord';

export interface TextSection {
text: string;
Expand Down
2 changes: 1 addition & 1 deletion test/utils/getSurroundingWord.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
/* eslint-disable jest/no-conditional-expect */
import '@testing-library/jest-dom';
import getSurroundingWord from '../../src/utils/getSurroundingWord';
import { getSurroundingWord } from '../../src/utils';

it('getSurroundingWord', () => {
expect(getSurroundingWord('hello world', 0)).toMatchObject({
Expand Down

0 comments on commit 0166a3c

Please sign in to comment.