Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
danyill committed Jan 30, 2025
1 parent 8036f7e commit 91ce401
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion foundation/plugin-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { targetLocales } from '../locales.js';

export type Plugin = {
name: string;
translations?: Record<typeof targetLocales[number], string>;
translations?: Record<(typeof targetLocales)[number], string>;
src: string;
icon: string;
requireDoc?: boolean;
Expand Down
16 changes: 16 additions & 0 deletions open-scd.editing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,22 @@ describe('open-scd', () => {
expect(editor.docName).to.equal('test.scd');
});

it('refreshes a document with the same name as one already opened on OpenDocEvent', async () => {
editor.dispatchEvent(newOpenEvent(sclDoc, 'test.scd'));
const firstUpdate = editor.updateComplete;
await firstUpdate;
sclDoc = new DOMParser().parseFromString(
util.sclDocString,
'application/xml'
);
editor.dispatchEvent(newOpenEvent(sclDoc, 'test.scd'));
const secondUpdate = editor.updateComplete;
await secondUpdate;
expect(firstUpdate).to.not.equal(secondUpdate);
expect(editor.doc).to.equal(sclDoc);
expect(editor.docName).to.equal('test.scd');
});

describe('with an SCL document loaded', () => {
beforeEach(async () => {
editor.dispatchEvent(newOpenEvent(sclDoc, 'test.scd'));
Expand Down
11 changes: 6 additions & 5 deletions open-scd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type Control = {

type RenderedPlugin = Control & { tagName: string };

type LocaleTag = typeof allLocales[number];
type LocaleTag = (typeof allLocales)[number];

const { getLocale, setLocale } = configureLocalization({
sourceLocale,
Expand Down Expand Up @@ -234,8 +234,9 @@ export class OpenSCD extends LitElement {
}

handleOpenDoc({ detail: { docName, doc } }: OpenEvent) {
this.docs[docName] = doc;
if (this.isEditable(docName)) this.docName = docName;
this.docName = docName;
this.docs[this.docName] = doc;
this.requestUpdate();
}

updateVersion(): void {
Expand Down Expand Up @@ -410,7 +411,7 @@ export class OpenSCD extends LitElement {
icon: plugin.icon,
getName: () =>
plugin.translations?.[
this.locale as typeof targetLocales[number]
this.locale as (typeof targetLocales)[number]
] || plugin.name,
isDisabled: () => (plugin.requireDoc && !this.docName) ?? false,
tagName: pluginTag(plugin.src),
Expand All @@ -433,7 +434,7 @@ export class OpenSCD extends LitElement {
icon: plugin.icon,
getName: () =>
plugin.translations?.[
this.locale as typeof targetLocales[number]
this.locale as (typeof targetLocales)[number]
] || plugin.name,
isDisabled: () => (plugin.requireDoc && !this.docName) ?? false,
tagName: pluginTag(plugin.src),
Expand Down

0 comments on commit 91ce401

Please sign in to comment.