From cebe4ced8ae88786db3598000bf9b85063005a6c Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Thu, 2 May 2019 11:17:06 -0400 Subject: [PATCH] Preserve user's preference for 'list'/'text' view for the raw tag editor --- modules/ui/raw_tag_editor.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/modules/ui/raw_tag_editor.js b/modules/ui/raw_tag_editor.js index 8fc8daacd..3d83424e5 100644 --- a/modules/ui/raw_tag_editor.js +++ b/modules/ui/raw_tag_editor.js @@ -13,6 +13,12 @@ import { utilArrayDifference, utilGetSetValue, utilNoAuto, utilRebind } from '.. export function uiRawTagEditor(context) { var taginfo = services.taginfo; var dispatch = d3_dispatch('change'); + var availableViews = [ + { id: 'text' }, + { id: 'list' } + ]; + + var _tagView = (context.storage('raw-tag-editor-view') || 'list'); // 'list, 'text' var _readOnlyTags = []; var _indexedKeys = []; var _showBlank = false; @@ -84,19 +90,20 @@ export function uiRawTagEditor(context) { .attr('class', 'raw-tag-options'); var optionEnter = optionsEnter.selectAll('.raw-tag-option') - .data(['text', 'list']) + .data(availableViews, function(d) { return d.id; }) .enter(); optionEnter .append('a') .attr('class', 'raw-tag-option') .attr('href', '#') - .text(function(d) { return d; }) + .text(function(d) { return d.id; }) .on('click', function(d) { + context.storage('raw-tag-editor-view', d.id); wrap.selectAll('.tag-text') - .classed('hide', (d === 'list')); + .classed('hide', (d.id !== 'text')); wrap.selectAll('.tag-list, .add-row') - .classed('hide', (d === 'text')); + .classed('hide', (d.id !== 'list')); }); @@ -105,7 +112,7 @@ export function uiRawTagEditor(context) { textarea = textarea.enter() .append('textarea') - .attr('class', 'tag-text hide') + .attr('class', 'tag-text' + (_tagView !== 'text' ? ' hide' : '')) .merge(textarea); textarea @@ -126,7 +133,7 @@ export function uiRawTagEditor(context) { list = list.enter() .append('ul') - .attr('class', 'tag-list') + .attr('class', 'tag-list' + (_tagView !== 'list' ? ' hide' : '')) .merge(list); @@ -135,7 +142,7 @@ export function uiRawTagEditor(context) { .data([0]) .enter() .append('div') - .attr('class', 'add-row'); + .attr('class', 'add-row' + (_tagView !== 'list' ? ' hide' : '')); addRowEnter .append('button')