Guest User

Untitled

a guest
Feb 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. diff --git a/blocks/rich-text/format-toolbar/index.js b/blocks/rich-text/format-toolbar/index.js
  2. index edc1c54a..b7750c82 100644
  3. --- a/blocks/rich-text/format-toolbar/index.js
  4. +++ b/blocks/rich-text/format-toolbar/index.js
  5. @@ -97,6 +97,7 @@ class FormatToolbar extends Component {
  6. }
  7.  
  8. addLink() {
  9. + this.props.highlightSelection();
  10. this.setState( { isEditingLink: false, isAddingLink: true, newLinkValue: '' } );
  11. }
  12.  
  13. diff --git a/blocks/rich-text/index.js b/blocks/rich-text/index.js
  14. index eeeebff9..85191057 100644
  15. --- a/blocks/rich-text/index.js
  16. +++ b/blocks/rich-text/index.js
  17. @@ -101,6 +101,7 @@ export default class RichText extends Component {
  18. this.maybePropagateUndo = this.maybePropagateUndo.bind( this );
  19. this.onPastePreProcess = this.onPastePreProcess.bind( this );
  20. this.onPaste = this.onPaste.bind( this );
  21. + this.highlightSelection = this.highlightSelection.bind( this );
  22.  
  23. this.state = {
  24. formats: {},
  25. @@ -660,6 +661,9 @@ export default class RichText extends Component {
  26. if ( document.activeElement !== this.editor.getBody() ) {
  27. return;
  28. }
  29. + if ( this.editor.selection.getNode().hasAttribute( 'data-mce-bogus' ) ) {
  30. + return;
  31. + }
  32. const formatNames = this.props.formattingControls;
  33. const formats = this.editor.formatter.matchAll( formatNames ).reduce( ( accFormats, activeFormat ) => {
  34. accFormats[ activeFormat ] = {
  35. @@ -766,6 +770,17 @@ export default class RichText extends Component {
  36. this.editor.setDirty( true );
  37. }
  38.  
  39. + highlightSelection() {
  40. + this.editor.undoManager.ignore( () => {
  41. + const id = this.editor.dom.uniqueId();
  42. + const content = this.editor.selection.getContent();
  43. + this.editor.selection.setContent(
  44. + `<span id="${ id }" style="background: rgba( 15, 155, 195, 0.2 )" data-mce-bogus="1">${ content }</span>`
  45. + );
  46. + this.editor.selection.select( this.editor.dom.get( id ) );
  47. + } );
  48. + }
  49. +
  50. render() {
  51. const {
  52. tagName: Tagname = 'div',
  53. @@ -800,6 +815,7 @@ export default class RichText extends Component {
  54. onChange={ this.changeFormats }
  55. enabledControls={ formattingControls }
  56. customControls={ formatters }
  57. + highlightSelection={ this.highlightSelection }
  58. />
  59. );
  60.  
  61. diff --git a/blocks/url-input/index.js b/blocks/url-input/index.js
  62. index a98d0df1..b6f596f8 100644
  63. --- a/blocks/url-input/index.js
  64. +++ b/blocks/url-input/index.js
  65. @@ -181,7 +181,7 @@ class UrlInput extends Component {
  66. return (
  67. <div className="blocks-url-input">
  68. <input
  69. - autoFocus
  70. + // autoFocus
  71. type="text"
  72. aria-label={ __( 'URL' ) }
  73. required
Add Comment
Please, Sign In to add comment