Skip to content

Commit

Permalink
Merge pull request #16 from mkslanc/closed-tab-restore-bug-fix
Browse files Browse the repository at this point in the history
tab data is saved in storage, no matter if it's closed or not
  • Loading branch information
mkslanc authored Apr 20, 2023
2 parents 6abd6ec + 803ecf9 commit 4414167
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {MenuManager, TabManager, CommandManager} from "ace-layout";
import {SAMPLES} from "./samples";
import {pathToTitle} from "./utils";
import {Layouts} from "./layouts/layouts";
import {createButtons, initTabs, runSample} from "./playground";
import {createButtons, getTabData, initTabs, runSample} from "./playground";

export function addMenu(callback) {
let menuManager = MenuManager.getInstance();
Expand Down Expand Up @@ -47,9 +47,8 @@ export function addMenu(callback) {

Object.keys(Layouts).forEach(function (i) {
let changeLayout = () => {
let storage = {};
let storage = getTabData();
let tabManager = TabManager.getInstance();
tabManager.saveTo(storage);
tabManager.setState({"main": Layouts[i]});
initTabs();
tabManager.restoreFrom(storage);
Expand Down
16 changes: 13 additions & 3 deletions src/playground.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Ace, AceLayout, Box, CommandManager, EditorType, MenuToolbar, TabManager} from "ace-layout";
import {Ace, AceEditor, AceLayout, Box, CommandManager, EditorType, MenuToolbar, TabManager} from "ace-layout";
import {addMenu} from "./menu";
import {pathToTitle, request} from "./utils";
import {generateTemplate} from "./template";
Expand Down Expand Up @@ -222,11 +222,21 @@ function saveSample() {
if (!currentPath)
return;

let storage = {};
tabManager.saveTo(storage);
let storage = getTabData();
localStorage[currentPath] = JSON.stringify(storage);
}

export function getTabData() {
let storage = {};
function saveTabData(tab: Tab<Ace.EditSession>) {
storage["@file@" + tab.path] = AceEditor.getSessionState(tab);
}
saveTabData(tabJs);
saveTabData(tabCSS);
saveTabData(tabHTML);
return storage;
}

function setTabValues(samples: [string, string, string]) {
tabJs.session.setValue(samples[0]);
tabCSS.session.setValue(samples[1]);
Expand Down

0 comments on commit 4414167

Please sign in to comment.