Path: blob/master/src/packages/frontend/editors/slate/search/search-control.tsx
1700 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import React from "react";6import { delay } from "awaiting";7import { Button } from "antd";8import { Icon } from "@cocalc/frontend/components";9import { ReactEditor } from "../slate-react";10import { selectNextMatch, selectPreviousMatch } from "./find-matches";1112interface Props {13decorate;14editor: ReactEditor;15disabled: boolean;16}1718export const SearchControlButtons: React.FC<Props> = ({19decorate,20editor,21disabled,22}) => {23return (24<div style={{ height: "23px" }}>25<Button26shape="round"27type="text"28size="small"29disabled={disabled}30style={{ padding: "0 5px" }}31onClick={() => previousMatch(editor, decorate)}32>33<Icon name="chevron-up" />34</Button>{" "}35<Button36shape="round"37size="small"38type="text"39disabled={disabled}40style={{ padding: "0 5px" }}41onClick={() => nextMatch(editor, decorate)}42>43<Icon name="chevron-down" />44</Button>45</div>46);47};4849export async function nextMatch(editor, decorate) {50const focused = ReactEditor.isFocused(editor);51if (!focused) {52ReactEditor.focus(editor);53await delay(0);54}55selectNextMatch(editor, decorate);56editor.scrollCaretIntoView();57await delay(100);58editor.scrollCaretIntoView();59}6061export async function previousMatch(editor, decorate) {62const focused = ReactEditor.isFocused(editor);63if (!focused) {64ReactEditor.focus(editor);65await delay(0);66}67selectPreviousMatch(editor, decorate);68editor.scrollCaretIntoView();69await delay(100);70editor.scrollCaretIntoView();71}727374