codemirror / dev

Development repository for the CodeMirror editor project
https://codemirror.net/
Other
5.94k stars 376 forks source link

Merge View: `highlightChanges` highlights entire multiple consequent full line insertions & deletions #1465

Closed VasylMarchuk closed 1 week ago

VasylMarchuk commented 1 week ago

Describe the issue

When highlightChanges option is enabled and whole chunks of code get removed or inserted, it highlights them all with red/green as if they were all "inline-modified", when in reality they really weren't.

Знімок екрана 2024-10-27 о 12 47 16

Details

It looks great for true inline changes as in example below, but unfortunately we had to disable this beautiful feature for now because it looks confusing (and quite ugly!) when multiple complete lines of code get inserted/deleted in bulk :(

Знімок екрана 2024-11-09 о 15 08 38

More details

We have been able to fix the visual look for the inserted lines with a sneaky .cm-insertedLine > .cm-changedText:only-child css rule, because an inserted line will always have one .cm-changedText if it's a completely new line... But for deletions that's not possible, because all deleted lines get crammed into one big .cm-deletedChunk 👀

Знімок екрана 2024-11-09 о 15 19 42

Example document, to reproduce:

{
  document:
      '-- Table: customer\nCREATE TABLE customer (\n\tid int  NOT NULL IDENTITY(1, 1),\n\tcustomer_name varchar(255)  NOT NULL,\n\tcity_id int  NOT NULL,\n\tcustomer_address varchar(255)  NOT NULL,\n\tnext_call_date date  NULL,\n\tts_inserted datetime  NOT NULL,\n\tCONSTRAINT customer_pk PRIMARY KEY  (id)\n);\n\n-- Table: customer_backup3\nCREATE TABLE customer_backup3 (\n\tid int  NOT NULL IDENTITY(1, 1),\n\tcustomer_name varchar(255)  NOT NULL,\n\tcity_id int  NOT NULL,\n\tcustomer_address varchar(255)  NOT NULL,\n\tnext_call_date date  NULL,\n\tts_inserted datetime  NOT NULL,\n\tCONSTRAINT customer_pk PRIMARY KEY  (id)\n);\n\n-- Extra comment\n-- Extra comment\n-- Extra comment\n-- Extra comment\n-- Extra comment\n\n-- Unchanged comment\n-- Unchanged comment\n-- Unchanged comment\n-- Unchanged comment\n-- Unchanged comment\n\n-- Unchanged comment\n-- Unchanged comment\n-- Unchanged comment\n-- Unchanged comment\n-- Unchanged comment',
  originalDocument:
      '-- Table: customer\nCREATE TABLE customer (\n\tid int  NOT NULL IDENTITY(1, 1),\n\tcustomer_name varchar(255)  NOT NULL,\n\tcity_id int  NOT NULL,\n\tcustomer_address varchar(255)  NOT NULL,\n\tnext_call_date date  NULL,\n\tts_inserted datetime  NOT NULL,\n\tCONSTRAINT customer_pk PRIMARY KEY  (id)\n);\n\n-- Table: customer_backup\nCREATE TABLE customer_backup (\n\tid int  NOT NULL IDENTITY(1, 1),\n\tcustomer_name varchar(255)  NOT NULL,\n\tcity_id int  NOT NULL,\n\tcustomer_address varchar(255)  NOT NULL,\n\tnext_call_date date  NULL,\n\tts_inserted datetime  NOT NULL,\n\tCONSTRAINT customer_pk PRIMARY KEY  (id)\n);\n\n-- Table: customer_backup3\nCREATE TABLE customer_backup3 (\n\tid int  NOT NULL IDENTITY(1, 1),\n\tcustomer_name varchar(255)  NOT NULL,\n\tcity_id int  NOT NULL,\n\tcustomer_address varchar(255)  NOT NULL,\n\tnext_call_date date  NULL,\n\tts_inserted datetime  NOT NULL,\n\tCONSTRAINT customer_pk PRIMARY KEY  (id)\n);\n\n-- Unchanged comment\n-- Unchanged comment\n-- Unchanged comment\n-- Unchanged comment\n-- Unchanged comment\n\n-- Unchanged comment\n-- Unchanged comment\n-- Unchanged comment\n-- Unchanged comment\n-- Unchanged comment',
  filename: 'test.sql',
  language: 'sql',
}

Reproduction link

We have a complete functioning demo of CodeMirror, wrapped into an Ember.js component over at https://app.codecrafters.io/demo/code-mirror, configurable with most of the standard extensions & their options in realtime, please feel free to test over there. It's ok if people discover the link here on GitHub, but please don't link to it, yet :)

Знімок екрана 2024-11-09 о 15 41 41

All of the documents used as examples in the Demo's document drop-down can be found here. The Ember.js component itself, which wraps CodeMirror, passes it all enabled extensions, and handles updates is here, just in case.

Our current CodeMirror & Merge versions

npm ls --depth=0 | grep codemirror
├── @codemirror/language-data@6.5.1
├── @codemirror/merge@6.7.2
├── @uiw/codemirror-theme-github@4.23.6
├── codemirror@6.0.1
marijnh commented 1 week ago

That style doesn't indicate 'inline modified', it indicates that that specific text is deleted/inserted, and I feel it'd be inconsistent to not apply it to entirely inserted/deleted lines. This really works as intended.