From 4089d5f8de814dc947028eec079c28b3824d3195 Mon Sep 17 00:00:00 2001 From: "Mr.VenomHare" Date: Tue, 18 Mar 2025 22:32:00 +0530 Subject: [PATCH 1/3] Added RTF Copy Feature --- client/modules/IDE/components/Editor/index.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/client/modules/IDE/components/Editor/index.jsx b/client/modules/IDE/components/Editor/index.jsx index 404741591a..7615a8bff5 100644 --- a/client/modules/IDE/components/Editor/index.jsx +++ b/client/modules/IDE/components/Editor/index.jsx @@ -204,6 +204,7 @@ class Editor extends React.Component { this._cm.on('keyup', this.handleKeyUp); } + this._cm.on('keydown', (_cm, e) => { // Show hint const mode = this._cm.getOption('mode'); From 8763faf8a269b6b75ffdb7bde0ff69b4e6b1b49f Mon Sep 17 00:00:00 2001 From: "Mr.VenomHare" Date: Tue, 18 Mar 2025 23:21:41 +0530 Subject: [PATCH 2/3] Added RTF to Cut event --- .../modules/IDE/components/Editor/index.jsx | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/client/modules/IDE/components/Editor/index.jsx b/client/modules/IDE/components/Editor/index.jsx index 7615a8bff5..359f124394 100644 --- a/client/modules/IDE/components/Editor/index.jsx +++ b/client/modules/IDE/components/Editor/index.jsx @@ -184,6 +184,40 @@ class Editor extends React.Component { [`${metaKey}-.`]: 'toggleComment' // Note: most adblockers use the shortcut ctrl+. }); + + const rtfCopy = (_cm, e) => { + e.preventDefault(); + const plaintext = _cm.doc.getSelection(); + const selectedElementsArr = document.getElementsByClassName( + 'CodeMirror-selectedtext' + ); + + let richText = plaintext[0] === '\n' ? '
' : ''; + let plaintextcounter = plaintext[0] === '\n' ? 1 : 0; + for (let i = 0; i < selectedElementsArr.length; i += 1) { + const { color, fontWeight, fontSize } = window.getComputedStyle( + selectedElementsArr[i] + ); + const cssToken = `color: ${color}; font-weight: ${fontWeight}; font-size: ${fontSize}`; + richText += `${selectedElementsArr[i].textContent}`; + plaintextcounter += selectedElementsArr[i].textContent.length; + while ( + plaintextcounter < plaintext.length && + plaintext[plaintextcounter] === '\n' + ) { + richText += '
'; + plaintextcounter += 1; + } + } + + try { + e.clipboardData.setData('text/html', richText); + e.clipboardData.setData('text/plain', plaintext); + } catch (error) { + console.error(error); + } + }; + this.initializeDocuments(this.props.files); this._cm.swapDoc(this._docs[this.props.file.id]); @@ -205,6 +239,12 @@ class Editor extends React.Component { } + this._cm.on('copy', rtfCopy); + this._cm.on('cut', (_em, e) => { + rtfCopy(_em, e); + _em.replaceSelection(''); + }); + this._cm.on('keydown', (_cm, e) => { // Show hint const mode = this._cm.getOption('mode'); From e6e9dfbed580a8cb4c3b96c7991a94cd4360264a Mon Sep 17 00:00:00 2001 From: "Mr.VenomHare" Date: Wed, 19 Mar 2025 18:28:36 +0530 Subject: [PATCH 3/3] Added Font Family to RTF Copy feature --- client/modules/IDE/components/Editor/index.jsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/client/modules/IDE/components/Editor/index.jsx b/client/modules/IDE/components/Editor/index.jsx index 359f124394..3b81e62b8a 100644 --- a/client/modules/IDE/components/Editor/index.jsx +++ b/client/modules/IDE/components/Editor/index.jsx @@ -184,21 +184,22 @@ class Editor extends React.Component { [`${metaKey}-.`]: 'toggleComment' // Note: most adblockers use the shortcut ctrl+. }); - const rtfCopy = (_cm, e) => { e.preventDefault(); const plaintext = _cm.doc.getSelection(); const selectedElementsArr = document.getElementsByClassName( 'CodeMirror-selectedtext' ); - let richText = plaintext[0] === '\n' ? '
' : ''; let plaintextcounter = plaintext[0] === '\n' ? 1 : 0; for (let i = 0; i < selectedElementsArr.length; i += 1) { - const { color, fontWeight, fontSize } = window.getComputedStyle( - selectedElementsArr[i] - ); - const cssToken = `color: ${color}; font-weight: ${fontWeight}; font-size: ${fontSize}`; + const { + color, + fontWeight, + fontSize, + fontFamily + } = window.getComputedStyle(selectedElementsArr[i]); + const cssToken = `color: ${color}; font-weight: ${fontWeight}; font-size: ${fontSize}; font-family: ${fontFamily}`; richText += `${selectedElementsArr[i].textContent}`; plaintextcounter += selectedElementsArr[i].textContent.length; while ( @@ -238,7 +239,6 @@ class Editor extends React.Component { this._cm.on('keyup', this.handleKeyUp); } - this._cm.on('copy', rtfCopy); this._cm.on('cut', (_em, e) => { rtfCopy(_em, e);