mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add option to remember zoom and scroll position in localStorage
This commit is contained in:
parent
5fc920087b
commit
d679b02658
@ -75,6 +75,8 @@
|
||||
"view": {
|
||||
"view": "View",
|
||||
"grid": "Grid",
|
||||
"storeZoom": "Restore zoom level on load",
|
||||
"storePosition": "Restore scroll position on load",
|
||||
"showGrid": "Show grid",
|
||||
"snapGrid": "Snap to grid",
|
||||
"gridSize": "Grid size",
|
||||
|
@ -121,6 +121,13 @@ RED.userSettings = (function() {
|
||||
// {setting:"theme", label:"Theme",options:function(done){ done([{val:'',text:'default'}].concat(RED.settings.theme("themes"))) }},
|
||||
// ]
|
||||
// },
|
||||
{
|
||||
title: "menu.label.view.view",
|
||||
options: [
|
||||
{setting:"view-store-zoom",label:"menu.label.view.storeZoom", default: false, toggle:true, onchange: function(val) { if (!val) { RED.settings.removeLocal("zoom-level")}}},
|
||||
{setting:"view-store-position",label:"menu.label.view.storePosition", default: false, toggle:true, onchange: function(val) { if (!val) { RED.settings.removeLocal("scroll-positions")}}},
|
||||
]
|
||||
},
|
||||
{
|
||||
title: "menu.label.view.grid",
|
||||
options: [
|
||||
|
@ -678,10 +678,38 @@ RED.view = (function() {
|
||||
show: function(n) { return !n.valid }
|
||||
})
|
||||
|
||||
if (RED.settings.get("editor.view.view-store-zoom")) {
|
||||
var userZoomLevel = parseFloat(RED.settings.getLocal('zoom-level'))
|
||||
if (!isNaN(userZoomLevel)) {
|
||||
scaleFactor = userZoomLevel
|
||||
}
|
||||
}
|
||||
|
||||
var userZoomLevel = parseFloat(RED.settings.getLocal('zoom-level'))
|
||||
if (!isNaN(userZoomLevel)) {
|
||||
scaleFactor = userZoomLevel
|
||||
var onScrollTimer = null;
|
||||
function storeScrollPosition() {
|
||||
workspaceScrollPositions[RED.workspaces.active()] = {
|
||||
left:chart.scrollLeft(),
|
||||
top:chart.scrollTop()
|
||||
};
|
||||
RED.settings.setLocal('scroll-positions', JSON.stringify(workspaceScrollPositions) )
|
||||
}
|
||||
chart.on("scroll", function() {
|
||||
if (RED.settings.get("editor.view.view-store-position")) {
|
||||
if (onScrollTimer) {
|
||||
clearTimeout(onScrollTimer)
|
||||
}
|
||||
onScrollTimer = setTimeout(storeScrollPosition, 200);
|
||||
}
|
||||
})
|
||||
|
||||
if (RED.settings.get("editor.view.view-store-position")) {
|
||||
var scrollPositions = RED.settings.getLocal('scroll-positions')
|
||||
if (scrollPositions) {
|
||||
try {
|
||||
workspaceScrollPositions = JSON.parse(scrollPositions)
|
||||
} catch(err) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1983,7 +2011,9 @@ RED.view = (function() {
|
||||
|
||||
RED.view.navigator.resize();
|
||||
redraw();
|
||||
RED.settings.setLocal('zoom-level', factor.toFixed(1))
|
||||
if (RED.settings.get("editor.view.view-store-zoom")) {
|
||||
RED.settings.setLocal('zoom-level', factor.toFixed(1))
|
||||
}
|
||||
}
|
||||
|
||||
function selectNone() {
|
||||
|
Loading…
Reference in New Issue
Block a user