Просмотр исходного кода

Merge branch 'feat/apply-and-replace-selected-text-when-create-link' into feat/show-link-path-preview

# Conflicts:
#	src/client/js/components/PageEditor/LinkEditModal.jsx
yusuketk 5 лет назад
Родитель
Сommit
ac84efdc89

+ 2 - 1
src/client/js/components/PageEditor/CodeMirrorEditor.jsx

@@ -653,7 +653,7 @@ export default class CodeMirrorEditor extends AbstractEditor {
   }
 
   showLinkEditHandler() {
-    this.linkEditModal.current.show();
+    this.linkEditModal.current.show(this.getCodeMirror());
   }
 
   showHandsonTableHandler() {
@@ -858,6 +858,7 @@ export default class CodeMirrorEditor extends AbstractEditor {
 
         <LinkEditModal
           ref={this.linkEditModal}
+          onSave={(link) => { return this.getCodeMirror().getDoc().replaceSelection(link) }}
         />
         <HandsontableModal
           ref={this.handsontableModal}

+ 16 - 2
src/client/js/components/PageEditor/LinkEditModal.jsx

@@ -19,18 +19,23 @@ class LinkEditModal extends React.PureComponent {
       linkInputValue: '',
       labelInputValue: '',
       linkerType: 'pukiwikiLink',
+      output: '[label](link)',
     };
 
+    this.show = this.show.bind(this);
+    this.hide = this.hide.bind(this);
     this.cancel = this.cancel.bind(this);
     this.toggleIsUseRelativePath = this.toggleIsUseRelativePath.bind(this);
     this.handleChangeLinkInput = this.handleChangeLinkInput.bind(this);
     this.handleChangeLabelInput = this.handleChangeLabelInput.bind(this);
     this.handleSelecteLinkerType = this.handleSelecteLinkerType.bind(this);
     this.showLog = this.showLog.bind(this);
+    this.save = this.save.bind(this);
   }
 
-  show() {
-    this.setState({ show: true });
+  show(editor) {
+    const selection = editor.getDoc().getSelection();
+    this.setState({ show: true, labelInputValue: selection });
   }
 
   cancel() {
@@ -77,6 +82,14 @@ class LinkEditModal extends React.PureComponent {
     this.setState({ linkerType });
   }
 
+
+  save() {
+    if (this.props.onSave != null) {
+      this.props.onSave(this.state.output);
+
+    this.hide();
+  }
+
   render() {
     const { pageContainer } = this.props;
     return (
@@ -202,6 +215,7 @@ class LinkEditModal extends React.PureComponent {
 
 LinkEditModal.propTypes = {
   pageContainer: PropTypes.instanceOf(PageContainer).isRequired,
+  onSave: PropTypes.func,
 };
 
 /**