Skip to content

Resolve conflicts in a click - #1882

Merged
fregante merged 36 commits into
refined-github:masterfrom
farnabaz:resolve-conflict
Mar 28, 2019
Merged

fregante merged 36 commits into
refined-github:masterfrom
farnabaz:resolve-conflict

Conversation

@farnabaz

@farnabaz farnabaz commented Mar 24, 2019 •

Copy link
Copy Markdown
Contributor

Add a single bar above every conflict in the editor. Closes #341
Screen Shot 2019-03-24 at 9 47 59 PM

@fregante fregante left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for this! I thought it was gonna be impossible!

And sorry for the many comments 😅

Comment thread source/features/resolve-conflict.tsx Resolved
Comment thread source/features/resolve-conflict.tsx Resolved
Comment thread source/features/resolve-conflict.tsx Resolved
Comment thread source/features/resolve-conflict.tsx Resolved
Comment thread source/features/resolve-conflict.tsx Resolved
Comment thread source/features/resolve-conflict.tsx Resolved
Comment thread source/features/resolve-conflict.tsx Resolved
Comment thread source/features/resolve-conflict.tsx Resolved
Comment thread source/features/resolve-conflict.tsx Resolved
Comment thread source/features/resolve-conflict.tsx Resolved
@fregante fregante changed the title feat(resolve-conflict): add helper widget in conflict editor Resolve conflicts in a click Mar 25, 2019
@fregante

This comment has been minimized.

@farnabaz

Copy link
Copy Markdown
Contributor Author

I'd resolve issues and pushed them. Thank you, I learned from your comments 😃

For the record, this feature doesn't work in Firefox because of CSP:

😨 I didn't test it on Firefox, I'll test and search around to see what we can do for it or do we have any other way

@fregante

Copy link
Copy Markdown
Member

Ok I think I found a solution. I'll push it here

@fregante

Copy link
Copy Markdown
Member

I created the base file, you can move the code in there

@fregante fregante left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is looking great already! I'm happy to see this working in Firefox as well!

These would be the last things I'd love to see, if manageable:

  1. Undo that works for the whole block, instead of line-by-line
  2. Undo that restores also the widget
  3. Quicker CodeMirror detection.

Edit: I think this is possible by waiting for the focus event of CodeMirror (this.editor.on('focus', processConflicts)), this would replace all setTimeouts and the swapDoc listener:

  • The file can be injected right away, the widget will wait for focus before being activated
  • The same focus event would also work when changing file

Comment thread source/resolve-conflicts.ts Resolved
Comment thread source/resolve-conflicts.ts Resolved
Comment thread source/resolve-conflicts.ts Resolved
@farnabaz

Copy link
Copy Markdown
Contributor Author

The file can be injected right away, the widget will wait for focus before being activated

It isn't possible, because there isn't any editor until first file load, so we cant listen editor.on('focus') on initial load, document.querySelector('.CodeMirror') return null without timeout

The same focus event would also work when changing file

focus calls everytime user interact with other parts of page and back to editor, it also calls when user navigate between tabs, I don't know is it ok to use focus for file change or not

@farnabaz

Copy link
Copy Markdown
Contributor Author

Undo that works for the whole block, instead of line-by-line

Oh nice, sure it's possible

Undo that restores also the widget

But I don't sure about this, because add/remove a widget is not a history change in CodeMirror

@fregante

Copy link
Copy Markdown
Member

there isn't any editor until first file load

The editor is there before the file load, but maybe not onDomReady. You can use:

await elementReady('.CodeMirror'); // *Not* safeElementReady
document.head.append(...);

add/remove a widget is not a history change in CodeMirror

That makes sense, is there an undo event that maybe you can listen to?

@fregante

Copy link
Copy Markdown
Member

focus calls everytime user interact with other parts of page and back to editor

That's fine, we can detect whether the widget was already added and avoid any further code execution.

@farnabaz

Copy link
Copy Markdown
Contributor Author

That makes sense, is there an undo event that maybe you can listen to?

Unfortunately not, but there is a change event, but it calls frequently with every change

@farnabaz

Copy link
Copy Markdown
Contributor Author

I've made changes to undo whole operations, it does not bring back widget yet but as we used focus event to add resolver widget, the widget added again on focus change

On initial load, we have a small issue, sometimes (because edit already gained its focus) widget does not show until next focus

@fregante

Copy link
Copy Markdown
Member

On initial load, we have a small issue, sometimes (because edit already gained its focus) widget does not show until next focus

I found a solution to that, I'll push something

The dom changes during the first `appendLineInfo` and the next `conflict` in the loop is no longer in the document, so we need to use the native CodeMirror loop
@fregante

This comment has been minimized.

Comment thread source/resolve-conflicts.ts Resolved
@farnabaz

farnabaz commented Mar 26, 2019 •

Copy link
Copy Markdown
Contributor Author

WoW, I can't even recognize these codes 👍 👍

@sindresorhus

sindresorhus commented Mar 27, 2019 •

Copy link
Copy Markdown
Member

The undo is not working correctly. I have to undo multiple times to get back to what I initially had before pressing one the accept buttons.


I tried it on the package-lock.json conflict we have in this PR, and clicking one of the buttons, causes the page to hang for 5 or more seconds for it to handle the change. The file is large, but there seems to be something slow going on. Manually fixing the text is not slow like this.


Pressing "Accept both changes" creates an invalid JSON. Not sure if this is the fault of the conflict resolver or Git though.

@fregante

fregante commented Mar 27, 2019 •

Copy link
Copy Markdown
Member

The undo is not working correctly. I have to undo multiple times to get back to what I initially had before pressing one the accept buttons.

Indeed. It worked perfectly on small files but on the big conflict right here is slow and has a multi-step undo (probably related issues since the undoability relies on the timestamp, I think)

Pressing "Accept both changes" creates an invalid JSON. Not sure if this is the fault of the conflict resolver or Git though.

That's normal, package-lock conflicts are to be solved via npm i. Same issue happens when merging CSS conflicts:

<<<<<<<
.red {
  color: red;
=======
.blue {
  color: blue;
>>>>>>>
}

@fregante

fregante commented Mar 27, 2019 •

Copy link
Copy Markdown
Member

Fixed! I used multi-selections to let the editor batch proper deleteLine commands.

The problem was GitHub's listener synchronously trying to update the conflict markers after every line deletion. With a DOM that big, each deletion took 500ms+

Now the whole "Accept incoming" operation takes 80ms on that page.

The only drawback is that now undo will also restore the selection on all the lines... which isn't terrible IMHO.

I'm leaving the conflict so you can test it.

@farnabaz

Copy link
Copy Markdown
Contributor Author

The only drawback is that now undo will also restore the selection on all the lines... which isn't terrible IMHO.

I used setSelection to remove multiple selections and select first line of conflict

@fregante
fregante merged commit 16b3781 into refined-github:master Mar 28, 2019
@fregante

Copy link
Copy Markdown
Member

Thanks for this feature @farnabaz! It'll be very useful 🌈

I used setSelection to remove multiple selections and select first line of conflict

Great! I forgot we were handling the undo already 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Fix merge conflict with both changes

3 participants