Skip to content

Commit

Permalink
Fix onivim#600 - Unsaved / modified file indication is not reliable (o…
Browse files Browse the repository at this point in the history
…nivim#672)

* Fix unsaved indicator

* Add integration test

* Formatting

* Update package/lockfiles
  • Loading branch information
bryphe authored and benox3 committed Aug 27, 2019
1 parent 1ba29c6 commit 74bfe59
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 26 deletions.
12 changes: 6 additions & 6 deletions bench.esy.lock/index.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "5d8d49c4abc581729cf191583f3cf646",
"checksum": "26dd12ee5e82368651f260dedd0dae40",
"root": "Oni2@link-dev:./package.json",
"node": {
"xmldom@0.1.27@d41d8cd9": {
Expand Down Expand Up @@ -246,13 +246,13 @@
],
"devDependencies": []
},
"reason-libvim@github:onivim/reason-libvim#56aa31a@d41d8cd9": {
"id": "reason-libvim@github:onivim/reason-libvim#56aa31a@d41d8cd9",
"reason-libvim@github:onivim/reason-libvim#b32b575@d41d8cd9": {
"id": "reason-libvim@github:onivim/reason-libvim#b32b575@d41d8cd9",
"name": "reason-libvim",
"version": "github:onivim/reason-libvim#56aa31a",
"version": "github:onivim/reason-libvim#b32b575",
"source": {
"type": "install",
"source": [ "github:onivim/reason-libvim#56aa31a" ]
"source": [ "github:onivim/reason-libvim#b32b575" ]
},
"overrides": [],
"dependencies": [
Expand Down Expand Up @@ -796,7 +796,7 @@
"revery@0.26.0@d41d8cd9", "reperf@1.4.0@d41d8cd9",
"rench@github:bryphe/rench#d8ebc99@d41d8cd9",
"reasonFuzz@github:CrossR/reasonFuzz#63d4056@d41d8cd9",
"reason-libvim@github:onivim/reason-libvim#56aa31a@d41d8cd9",
"reason-libvim@github:onivim/reason-libvim#b32b575@d41d8cd9",
"reason-jsonrpc@1.1.0@d41d8cd9", "reason-glfw@3.2.1027@d41d8cd9",
"ocaml@4.7.1004@d41d8cd9", "isolinear@2.0.0@d41d8cd9",
"esy-macdylibbundler@0.4.5@d41d8cd9",
Expand Down
12 changes: 6 additions & 6 deletions esy.lock/index.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "5d8d49c4abc581729cf191583f3cf646",
"checksum": "26dd12ee5e82368651f260dedd0dae40",
"root": "Oni2@link-dev:./package.json",
"node": {
"xmldom@0.1.27@d41d8cd9": {
Expand Down Expand Up @@ -246,13 +246,13 @@
],
"devDependencies": []
},
"reason-libvim@github:onivim/reason-libvim#56aa31a@d41d8cd9": {
"id": "reason-libvim@github:onivim/reason-libvim#56aa31a@d41d8cd9",
"reason-libvim@github:onivim/reason-libvim#b32b575@d41d8cd9": {
"id": "reason-libvim@github:onivim/reason-libvim#b32b575@d41d8cd9",
"name": "reason-libvim",
"version": "github:onivim/reason-libvim#56aa31a",
"version": "github:onivim/reason-libvim#b32b575",
"source": {
"type": "install",
"source": [ "github:onivim/reason-libvim#56aa31a" ]
"source": [ "github:onivim/reason-libvim#b32b575" ]
},
"overrides": [],
"dependencies": [
Expand Down Expand Up @@ -796,7 +796,7 @@
"revery@0.26.0@d41d8cd9",
"rench@github:bryphe/rench#d8ebc99@d41d8cd9",
"reasonFuzz@github:CrossR/reasonFuzz#63d4056@d41d8cd9",
"reason-libvim@github:onivim/reason-libvim#56aa31a@d41d8cd9",
"reason-libvim@github:onivim/reason-libvim#b32b575@d41d8cd9",
"reason-jsonrpc@1.1.0@d41d8cd9", "reason-glfw@3.2.1027@d41d8cd9",
"ocaml@4.7.1004@d41d8cd9", "isolinear@2.0.0@d41d8cd9",
"esy-macdylibbundler@0.4.5@d41d8cd9",
Expand Down
47 changes: 47 additions & 0 deletions integration_test/RegressionFileModifiedIndicationTest.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
open Oni_Model;
open Oni_IntegrationTestLib;

// Regression test case covering #600:
// https://github.com/onivim/oni2/issues/600
//
// Verify some simple cases around the file modified flag
runTest(~name="RegressionFileModifiedIndication", (_, wait, _) => {
wait(~name="Initial mode is normal", (state: State.t) =>
state.mode == Vim.Types.Normal
);

Vim.command("e regression-file-modified-indication.txt");

let id = Vim.Buffer.getCurrent() |> Vim.Buffer.getId;

Vim.input("o");
Vim.input("a");

let validateBufferCondition = (f, state: State.t) => {
let buffer = Selectors.getBufferById(state, id);
switch (buffer) {
| Some(v) => f(v)
| None => false
};
};

wait(~name="Wait for modified flag to be set", (state: State.t) =>
validateBufferCondition(b => Buffer.isModified(b) == true, state)
);

// Save file, should clear modified flag
Vim.input("<esc>");
Vim.command("w");

wait(~name="Wait for modified flag to be set", (state: State.t) =>
validateBufferCondition(b => Buffer.isModified(b) == false, state)
);

// Make another modification, should set it again
Vim.input("o");
Vim.input("a");

wait(~name="Wait for modified flag to be set", (state: State.t) =>
validateBufferCondition(b => Buffer.isModified(b) == true, state)
);
});
2 changes: 2 additions & 0 deletions integration_test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
QuickOpenDoesntLeakFileDescriptorsTest
SearchShowClearHighlightsTest
RegressionCommandLineNoCompletionTest
RegressionFileModifiedIndicationTest
RegressionVspEmptyInitialBufferTest
RegressionVspEmptyExistingBufferTest
TickTest
Expand Down Expand Up @@ -37,6 +38,7 @@
QuickOpenEventuallyCompletesTest.exe
QuickOpenDoesntLeakFileDescriptorsTest.exe
RegressionCommandLineNoCompletionTest.exe
RegressionFileModifiedIndicationTest.exe
RegressionVspEmptyInitialBufferTest.exe
RegressionVspEmptyExistingBufferTest.exe
SearchShowClearHighlightsTest.exe
Expand Down
12 changes: 6 additions & 6 deletions integrationtest.esy.lock/index.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "5d8d49c4abc581729cf191583f3cf646",
"checksum": "26dd12ee5e82368651f260dedd0dae40",
"root": "Oni2@link-dev:./package.json",
"node": {
"xmldom@0.1.27@d41d8cd9": {
Expand Down Expand Up @@ -246,13 +246,13 @@
],
"devDependencies": []
},
"reason-libvim@github:onivim/reason-libvim#56aa31a@d41d8cd9": {
"id": "reason-libvim@github:onivim/reason-libvim#56aa31a@d41d8cd9",
"reason-libvim@github:onivim/reason-libvim#b32b575@d41d8cd9": {
"id": "reason-libvim@github:onivim/reason-libvim#b32b575@d41d8cd9",
"name": "reason-libvim",
"version": "github:onivim/reason-libvim#56aa31a",
"version": "github:onivim/reason-libvim#b32b575",
"source": {
"type": "install",
"source": [ "github:onivim/reason-libvim#56aa31a" ]
"source": [ "github:onivim/reason-libvim#b32b575" ]
},
"overrides": [],
"dependencies": [
Expand Down Expand Up @@ -796,7 +796,7 @@
"revery@0.26.0@d41d8cd9",
"rench@github:bryphe/rench#d8ebc99@d41d8cd9",
"reasonFuzz@github:CrossR/reasonFuzz#63d4056@d41d8cd9",
"reason-libvim@github:onivim/reason-libvim#56aa31a@d41d8cd9",
"reason-libvim@github:onivim/reason-libvim#b32b575@d41d8cd9",
"reason-jsonrpc@1.1.0@d41d8cd9", "reason-glfw@3.2.1027@d41d8cd9",
"ocaml@4.7.1004@d41d8cd9", "isolinear@2.0.0@d41d8cd9",
"esy-macdylibbundler@0.4.5@d41d8cd9",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
"@opam/ocaml-migrate-parsetree": "1.3.1",
"@opam/ppx_tools_versioned": "5.2.2",
"revery": "0.26.0",
"reason-libvim": "github:onivim/reason-libvim#56aa31a",
"reason-libvim": "github:onivim/reason-libvim#b32b575",
"reason-fontkit": "2.5.0",
"@opam/camomile": "1.0.1",
"@opam/ocamlfind": "1.8.0",
Expand Down
2 changes: 1 addition & 1 deletion src/editor/Model/Actions.re
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type t =
| BufferUpdate(BufferUpdate.t)
| BufferSaved(Vim.BufferMetadata.t)
| BufferSetIndentation(int, IndentationSettings.t)
| BufferMarkDirty(int)
| BufferSetModified(int, bool)
| Command(string)
| ConfigurationReload
| ConfigurationSet(Configuration.t)
Expand Down
8 changes: 8 additions & 0 deletions src/editor/Model/Buffer.re
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ let getLine = (buffer: t, line: int) => buffer.lines[line];

let isModified = (buffer: t) => buffer.metadata.modified;

let setModified = (modified: bool, buffer: t) => {
...buffer,
metadata: {
...buffer.metadata,
modified,
},
};

let isSyntaxHighlightingEnabled = (buffer: t) =>
buffer.syntaxHighlightingEnabled;
let disableSyntaxHighlighting = (buffer: t) => {
Expand Down
1 change: 1 addition & 0 deletions src/editor/Model/Buffer.rei
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ let isSyntaxHighlightingEnabled: t => bool;
let isIndentationSet: t => bool;
let setIndentation: (IndentationSettings.t, t) => t;
let getIndentation: t => option(IndentationSettings.t);
let setModified: (bool, t) => t;
let disableSyntaxHighlighting: t => t;

let update: (t, BufferUpdate.t) => t;
Expand Down
5 changes: 5 additions & 0 deletions src/editor/Model/Buffers.re
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ let setIndentation = indent =>
let disableSyntaxHighlighting =
ofBufferOpt(buffer => Buffer.disableSyntaxHighlighting(buffer));

let setModified = modified =>
ofBufferOpt(buffer => Buffer.setModified(modified, buffer));

let reduce = (state: t, action: Actions.t) => {
switch (action) {
| BufferDisableSyntaxHighlighting(id) =>
Expand All @@ -70,6 +73,8 @@ let reduce = (state: t, action: Actions.t) => {
};
IntMap.update(metadata.id, f, state);
/* | BufferDelete(bd) => IntMap.remove(bd, state) */
| BufferSetModified(id, modified) =>
IntMap.update(id, setModified(modified), state)
| BufferSetIndentation(id, indent) =>
IntMap.update(id, setIndentation(indent), state)
| BufferUpdate(bu) => IntMap.update(bu.id, applyBufferUpdate(bu), state)
Expand Down
11 changes: 11 additions & 0 deletions src/editor/Store/VimStoreConnector.re
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ let start =
dispatch(Model.Actions.BufferEnter(meta));
});

let _ =
Vim.Buffer.onModifiedChanged((id, modified) => {
Log.info(
"Buffer metadata changed: "
++ string_of_int(id)
++ " | "
++ string_of_bool(modified),
);
dispatch(Model.Actions.BufferSetModified(id, modified));
});

let _ =
Vim.Cursor.onMoved(newPosition => {
let cursorPos =
Expand Down
12 changes: 6 additions & 6 deletions test.esy.lock/index.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "5d8d49c4abc581729cf191583f3cf646",
"checksum": "26dd12ee5e82368651f260dedd0dae40",
"root": "Oni2@link-dev:./package.json",
"node": {
"xmldom@0.1.27@d41d8cd9": {
Expand Down Expand Up @@ -246,13 +246,13 @@
],
"devDependencies": []
},
"reason-libvim@github:onivim/reason-libvim#56aa31a@d41d8cd9": {
"id": "reason-libvim@github:onivim/reason-libvim#56aa31a@d41d8cd9",
"reason-libvim@github:onivim/reason-libvim#b32b575@d41d8cd9": {
"id": "reason-libvim@github:onivim/reason-libvim#b32b575@d41d8cd9",
"name": "reason-libvim",
"version": "github:onivim/reason-libvim#56aa31a",
"version": "github:onivim/reason-libvim#b32b575",
"source": {
"type": "install",
"source": [ "github:onivim/reason-libvim#56aa31a" ]
"source": [ "github:onivim/reason-libvim#b32b575" ]
},
"overrides": [],
"dependencies": [
Expand Down Expand Up @@ -796,7 +796,7 @@
"revery@0.26.0@d41d8cd9",
"rench@github:bryphe/rench#d8ebc99@d41d8cd9",
"reasonFuzz@github:CrossR/reasonFuzz#63d4056@d41d8cd9",
"reason-libvim@github:onivim/reason-libvim#56aa31a@d41d8cd9",
"reason-libvim@github:onivim/reason-libvim#b32b575@d41d8cd9",
"reason-jsonrpc@1.1.0@d41d8cd9", "reason-glfw@3.2.1027@d41d8cd9",
"ocaml@4.7.1004@d41d8cd9", "isolinear@2.0.0@d41d8cd9",
"esy-macdylibbundler@0.4.5@d41d8cd9",
Expand Down

0 comments on commit 74bfe59

Please sign in to comment.