mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-19 11:21:41 +03:00
applying snippet
This commit is contained in:
parent
4ed29a9d84
commit
53c5686617
11
src/components/markdownEditor/view/formats/applySnippet.ts
Normal file
11
src/components/markdownEditor/view/formats/applySnippet.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import {replaceBetween } from './utils';
|
||||
|
||||
export default async ({ text, selection, setTextAndSelection, snippetText}) => {
|
||||
|
||||
const newText = replaceBetween(text, selection, `\n${snippetText}\n`);
|
||||
const newSelection = {
|
||||
start: selection.start + 1,
|
||||
end: selection.start + 1 + (snippetText && snippetText.length),
|
||||
};
|
||||
setTextAndSelection({ text: newText, selection: newSelection });
|
||||
};
|
@ -85,8 +85,8 @@ export default EStyleSheet.create({
|
||||
modalStyle: {
|
||||
flex: 1,
|
||||
backgroundColor: '$primaryBackgroundColor',
|
||||
margin:0,
|
||||
paddingTop:32,
|
||||
paddingBottom:16
|
||||
margin: 0,
|
||||
paddingTop: 32,
|
||||
paddingBottom: 16,
|
||||
},
|
||||
});
|
||||
|
@ -39,6 +39,7 @@ import { ThemeContainer } from '../../../containers';
|
||||
|
||||
// Styles
|
||||
import styles from './markdownEditorStyles';
|
||||
import applySnippet from './formats/applySnippet';
|
||||
|
||||
const MarkdownEditorView = ({
|
||||
draftBody,
|
||||
@ -195,6 +196,15 @@ const MarkdownEditorView = ({
|
||||
</ScrollView>
|
||||
);
|
||||
|
||||
const _handleOnSnippetSelect = (snippetText) => {
|
||||
applySnippet({
|
||||
text,
|
||||
selection,
|
||||
setTextAndSelection: _setTextAndSelection,
|
||||
snippetText,
|
||||
});
|
||||
};
|
||||
|
||||
const _renderMarkupButton = ({ item }) => (
|
||||
<View style={styles.buttonWrapper}>
|
||||
<IconButton
|
||||
@ -353,7 +363,7 @@ const MarkdownEditorView = ({
|
||||
animationType="slide"
|
||||
style={styles.modalStyle}
|
||||
>
|
||||
<SnippetsModal username={currentAccount.username} handleOnSelect={_setTextAndSelection} />
|
||||
<SnippetsModal username={currentAccount.username} handleOnSelect={_handleOnSnippetSelect} />
|
||||
</Modal>
|
||||
<ActionSheet
|
||||
ref={galleryRef}
|
||||
|
@ -9,9 +9,12 @@ import SnippetEditorModal, { SnippetEditorModalRef } from '../snippetEditorModal
|
||||
import SnippetItem from './snippetItem';
|
||||
import { Snippet } from '../../models';
|
||||
|
||||
interface SnippetsModalProps {
|
||||
username:string,
|
||||
handleOnSelect:(snippetText:string)=>void,
|
||||
}
|
||||
|
||||
|
||||
const SnippetsModal = ({ username, handleOnSelect }) => {
|
||||
const SnippetsModal = ({ username, handleOnSelect }:SnippetsModalProps) => {
|
||||
const editorRef = useRef<SnippetEditorModalRef>(null);
|
||||
const intl = useIntl();
|
||||
console.log('username', username);
|
||||
@ -61,7 +64,7 @@ const SnippetsModal = ({ username, handleOnSelect }) => {
|
||||
//render list item for snippet and handle actions;
|
||||
const _renderItem = ({ item, index }:{item:Snippet, index:number}) => {
|
||||
|
||||
const _onPress = () => handleOnSelect({ text: item.body, selection: { start: 0, end: 0 } })
|
||||
const _onPress = () => handleOnSelect(item.body)
|
||||
|
||||
const _onRemovePress = () => {
|
||||
_removeSnippet(item.id);
|
||||
|
Loading…
Reference in New Issue
Block a user