GrapesJS / grapesjs

Free and Open source Web Builder Framework. Next generation tool for building templates without coding
https://grapesjs.com
BSD 3-Clause "New" or "Revised" License
22.13k stars 4.02k forks source link

Insert Text at cursor position inside text #492

Closed sarathksasi closed 6 years ago

sarathksasi commented 6 years ago

Hi,

We are evaluating GrapesJS for one of requirement. As part of the evaluation i am creating custom command 'insert placeholder', what it does is ( what i am planning to do ) is when a select Text and when i click this command , it should insert text at the selected cursor position.

Initially i had done this

var existingData = selectedComponent.view.el.firstChild.data;

      var placeHolderData = '[[1# PlaceHolder Name]]';
      existingData = existingData + " "+placeHolderData;

        console.log("existingData ",existingData); 

      selectedComponent.set('content', existingData);

this is only appending text. My requirement is insert at given cursor position. It will be great anybody can quickly come up with a solution for this ?

Thanks in Advance Sarath K S

mathieuk commented 6 years ago

Duplicate with #481

sarathksasi commented 6 years ago

Thanks

edwardjiawei commented 6 years ago

Similar to what I did in grapesjs-plugin-customrte. But I no propose my code to be based on, at it is mess.

You should able to test the code in design,html in my repo.

Also can set lower priority for implement el.contentEditable, so that the placeholder text is not editable. #287

If it is a block then grapesjs have default great option: removable: false, // Once inserted it can't be removed

Final, thanks for the good freedom work for artf. There is a lot of priority in grapesjs, maybe can shift to community plugin (artf/api-richtexteditor-plugin), maybe artf can decide to initiate the repo for #481. So we can contribute when all of the requester if free.

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.