Skip to content

Commit

Permalink
State: Use tab state from application state (onivim#26)
Browse files Browse the repository at this point in the history
* Hook up tab state

* Formatting
  • Loading branch information
bryphe authored Feb 6, 2019
1 parent be338e3 commit 952a04f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/editor/Core/Reducer.re
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let reduce: (State.t, Actions.t) => State.t =
(s, a) => {
switch (a) {
| ChangeMode(m) =>
let ret: State.t = {mode: m};
let ret: State.t = {...s, mode: m};
ret;
| Noop => s
};
Expand Down
18 changes: 16 additions & 2 deletions src/editor/Core/State.re
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ module Mode = {
};
};

type t = {mode: Mode.t};
module Tab = {
type t = {
id: int,
title: string,
active: bool,
};

let create: unit => t = () => {mode: Insert};
let create = (id, title) => {id, title, active: false};
};

type t = {
mode: Mode.t,
tabs: list(Tab.t),
};

let create: unit => t =
() => {mode: Insert, tabs: [Tab.create(0, "[No Name]")]};
26 changes: 18 additions & 8 deletions src/editor/UI/Editor.re
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ open Revery.UI;

let noop = () => ();

let tabs: list(Tabs.tabInfo) = [
{title: "file1.re", active: true, onClick: noop, onClose: noop},
{title: "file2.re", active: false, onClick: noop, onClose: noop},
{title: "file3.re", active: false, onClick: noop, onClose: noop},
];

let component = React.component("Editor");

let editorViewStyle = (background, foreground) =>
Expand All @@ -30,13 +24,29 @@ let editorViewStyle = (background, foreground) =>
flexDirection(`Column),
];

let make = () =>
let toUiTabs = (tabs: list(Oni_Core.State.Tab.t)) => {
let f = (t: Oni_Core.State.Tab.t) => {
let ret: Tabs.tabInfo = {
title: t.title,
active: t.active,
onClick: noop,
onClose: noop,
};
ret;
};

List.map(f, tabs);
};

let make = (state: Oni_Core.State.t) =>
component((_slots: React.Hooks.empty) => {
let theme = Theme.get();

let tabs = toUiTabs(state.tabs);
let style = editorViewStyle(theme.background, theme.foreground);

<View style> <Tabs tabs /> <EditorSurface /> </View>;
});

let createElement = (~children as _, ()) => React.element(make());
let createElement = (~state: Oni_Core.State.t, ~children as _, ()) =>
React.element(make(state));
2 changes: 1 addition & 1 deletion src/editor/UI/Root.re
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ let make = (state: State.t) =>
let style = rootStyle(theme.background, theme.foreground);

<View style>
<View style=surfaceStyle> <Editor /> </View>
<View style=surfaceStyle> <Editor state /> </View>
<View style=statusBarStyle> <StatusBar mode={state.mode} /> </View>
</View>;
});
Expand Down

0 comments on commit 952a04f

Please sign in to comment.