Skip to content

Keep LineBreaks in pasted code #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aktion-hip
Copy link

Adjusted function insert(). Lines 507 ff:

function insert(text: string) {
    text = text
      .replace(/&/g, '&')
      .replace(/</g, '&lt;')
      .replace(/>/g, '&gt;')
      .replace(/"/g, '&quot;')
      .replace(/'/g, '&#039;')
      .replace(/\n/g, '<br>')
    document.execCommand('insertHTML', false, text)
  }

Added .replace(/\n/g, '<br>') to keep line breaks for content pasted into code input area.

@@ -223,7 +223,7 @@ export function CodeJar(editor: HTMLElement, highlight: (e: HTMLElement, pos?: P

// Flip start and end if the direction reversed
if (pos.dir == '<-') {
const {start, end} = pos
const { start, end } = pos
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets keep style as is for now

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for this change, that was not intended.

@@ -511,6 +511,7 @@ export function CodeJar(editor: HTMLElement, highlight: (e: HTMLElement, pos?: P
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;')
.replace(/\n/g, '<br>')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about not-ff? Ib those plain-text mode \n is supported.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, this problem exists only using FF. I now can confirm that pasting multiline code works without problems using Edge or Chrome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants