Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.
This repository was archived by the owner on Apr 16, 2026. It is now read-only.

Line-based Copy/Paste has different behavior on Windows vs. Linux #6337

Closed

Description

@lincolnpgoog

When using line-based (no highlighting) copy-paste, there is different behavior between Windows and Linux. The Linux behavior is preferred, as it is similar to other text or code editors like Notepad++ or Visual Studio.

Environments Tested

Browsers Tested:

  • Chrome 83.0.4103.116 (Official Build) (64-bit) on Windows 10 Version 1903
  • Chrome 83.0.4103.112 (Official Build) (64-bit) on ChromeOS

I'm not sure what version of CodeMirror is being used, but my example was created using the https://codemirror.net demo box at the time of writing up this issue.

Steps to Reproduce

  1. Visit https://codemirror.net/ in the browser
  2. Using the demo panel on the page, place the cursor anywhere in the middle of a line of text. Do not highlight any text.
  3. Press Ctrl+C to copy the line.
  4. Move the cursor to any other line of text, anywhere within the line. Do not highlight any text.
  5. Press Ctrl+V to paste. This is where the behavior differs.

Example

In the example that follows | indicate the copy position, and ^ indicates the paste position:

<!-- Create a simple CodeMirror instance -->
<link rel="stylesheet" href="lib/codemirror.css">
<script src="lib/codemirror.js"></script>
<script>
  var editor = CodeMirr|or.fromTextArea(myTextarea, {
    lineNum^bers: true
  });
</script>

On ChromeOS/Linux, this is the result, which is desirable and expected:

<!-- Create a simple CodeMirror instance -->
<link rel="stylesheet" href="lib/codemirror.css">
<script src="lib/codemirror.js"></script>
<script>
  var editor = CodeMirror.fromTextArea(myTextarea, {
  var editor = CodeMirror.fromTextArea(myTextarea, {
    lineNumbers: true
  });
</script>

On Windows, this is the result, which is problematic and unexpected (note that the line was embedded in the middle of the paste position, rather than being placed above it):

<!-- Create a simple CodeMirror instance -->
<link rel="stylesheet" href="lib/codemirror.css">
<script src="lib/codemirror.js"></script>
<script>
  var editor = CodeMirror.fromTextArea(myTextarea, {
    lineNum  var editor = CodeMirror.fromTextArea(myTextarea, {
bers: true
  });
</script>

As someone who regularly switches between Windows and Linux, it would be useful to be consistent between the versions, preferably in favor of the way the Linux version handles it. Thanks!

Activity

  1. marijnh commented on Jul 8, 2020

    @marijnh
    Member

    This was caused by the code getting confused by \r characters in the pasted text. Attached patch seems to fix it.

  2. added a commit that references this issue on Oct 31, 2020
    14d7274
  3. added a commit that references this issue on May 1, 2024
    b5ce22f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions