Skip to content
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

Don't mark YAML editor as immediately changed #1666

Merged
merged 1 commit into from
Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/scripts/controllers/edit/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ angular.module('openshiftConsole')
var session = editor.getSession();
session.setOption('tabSize', 2);
session.setOption('useSoftTabs', true);
session.on('change', onChange);

// Wait for the editor to initialize before adding the on change handler
// so it's not immediately marked as modified.
setTimeout(function() {
Copy link
Member

Choose a reason for hiding this comment

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

is this always going to work or are we creating a race condition where it will just work most of the time

Copy link
Member Author

Choose a reason for hiding this comment

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

I can't find a cleaner way. It always works in my testing.

We could do something like this:

    // onChange is called once when the initial content is loaded in the editor.
    var initialized = false;
    $scope.onChange = function() {
      if (initialized) {
        $scope.modified = true;
      }

      initialized = true;
    };

I worry that this will break if they ever change the behavior so that initialization doesn't trigger onChange, however.

Open to alternatives. The worst that happens is that the editor is incorrectly marked dirty so you're prompted when pressing the back button.

session.on('change', onChange);
});
};

var watches = [];
Expand Down
4 changes: 3 additions & 1 deletion dist/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7465,7 +7465,9 @@ a.modified = !0;
}, 1e3);
a.aceLoaded = function(a) {
var b = a.getSession();
b.setOption("tabSize", 2), b.setOption("useSoftTabs", !0), b.on("change", o);
b.setOption("tabSize", 2), b.setOption("useSoftTabs", !0), setTimeout(function() {
b.on("change", o);
});
};
var p = [];
l.get(d.project).then(_.spread(function(c, e) {
Expand Down