monaco-editor icon indicating copy to clipboard operation
monaco-editor copied to clipboard

Go to Next Difference doesn't work

Open demonguy opened this issue 3 years ago • 6 comments

**monaco-editor version: official playgournd 0.25.2 **Browser: chrome **OS: windows 10 Playground code that reproduces the issue:

Here is the sample, according to my understanding, Go to Next Difference(F7)" should jump to the last line which has difference. However, it behaves like Select Next Word. Just jump to the next word which is the same as my cursor point to.

var originalModel = monaco.editor.createModel("1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\nheLLo world!", "text/plain");
var modifiedModel = monaco.editor.createModel("1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\nhello orlando!", "text/plain");

var diffEditor = monaco.editor.createDiffEditor(document.getElementById("container"));
diffEditor.setModel({
	original: originalModel,
	modified: modifiedModel
});

demonguy avatar Jun 30 '21 02:06 demonguy

Is it a confirmed bug? or only i can reproduce it?

demonguy avatar Jul 02 '21 08:07 demonguy

I can also confirm the bug.

I'll try to look into this next milestone, but you would help us a lot with a pull request if you can find the bug!

hediet avatar Jul 02 '21 12:07 hediet

I'm also looking at it. But i'm new to javascript

demonguy avatar Jul 02 '21 17:07 demonguy

The following code contains the reason to Go to Next difference (F7) bug and have corresponding comments The following code is in min/VS/Editor/editor.main.js

      class N extends c.EditorAction {
            constructor() {
                super({
                    id: "editor.action.diffReview.next",
                    label: i.localize(10, null),
                    alias: "Go to Next Difference",
                    precondition: v.ContextKeyExpr.has("isInDiffEditor"),
                    kbOpts: {kbExpr: null, primary: 65, weight: 100}
                })
            }

            run(e, t) {
                const i = M(e);//Because M(e) return null, i = null
                i && i.diffReviewNext()//Because i = null, i.diffreviewnext() will not be executed
            }
        }
        
        function M(e) {
            const t = e.get(h.ICodeEditorService), i = t.listDiffEditors(), n = t.getActiveCodeEditor();//n=null
            if (!n) return null;//In JavaScript ! Null is true, so M(e) also return null
            for (let e = 0, t = i.length; e < t; e++) {
                const t = i[e]
                ;
                if (t.getModifiedEditor().getId() === n.getId() || t.getOriginalEditor().getId() === n.getId()) return t
            }
            return null
        }
        
         class s extends o.CodeEditorServiceImpl {
            getActiveCodeEditor() {
                return null
            }
                ...
            }

1819981451 avatar Jul 12 '21 09:07 1819981451

You can find the unminified code here.

I guess the question is why t.getActiveCodeEditor returns null.

hediet avatar Jul 13 '21 07:07 hediet

I don't know exactly why t.getActiveCodeEditor returns null, but it seems that its setActiveCodeEditor has never been called

1819981451 avatar Jul 15 '21 06:07 1819981451