Skip to content

Commit 8b96a64

Browse files
committed
When adding new envelopes or effects in full screen mode, auto-scroll to ensure new settings are visible.
1 parent c77ff48 commit 8b96a64

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

editor/SongDocument.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ export class SongDocument {
5353
public channelScrollPos: number = 0;
5454
public prompt: string | null = null;
5555

56+
public addedEffect: boolean = false;
57+
public addedEnvelope: boolean = false;
58+
5659
private static readonly _maximumUndoHistory: number = 100;
5760
private _recovery: SongRecovery = new SongRecovery();
5861
private _recoveryUid: string;

editor/SongEditor.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ export class SongEditor {
339339
this._barScrollBar.container,
340340
);
341341

342+
private readonly _instrumentSettingsArea: HTMLDivElement = div({class: "instrument-settings-area"}, this._instrumentSettingsGroup);
342343
private readonly _settingsArea: HTMLDivElement = div({class: "settings-area noSelection"},
343344
div({class: "version-area"},
344345
div({style: `text-align: center; margin: 3px 0; color: ${ColorConfig.secondaryText};`}, EditorConfig.versionDisplayName),
@@ -391,9 +392,7 @@ export class SongEditor {
391392
),
392393
),
393394
),
394-
div({class: "instrument-settings-area"},
395-
this._instrumentSettingsGroup,
396-
),
395+
this._instrumentSettingsArea,
397396
);
398397

399398
public readonly mainLayer: HTMLDivElement = div({class: "beepboxEditor", tabIndex: "0"},
@@ -988,6 +987,22 @@ export class SongEditor {
988987
if (this._doc.autoFollow && !this._doc.synth.playing) {
989988
this._doc.synth.goToBar(this._doc.bar);
990989
}
990+
991+
// When adding effects or envelopes to an instrument in fullscreen modes,
992+
// auto-scroll the settings areas to ensure the new settings are visible.
993+
if (this._doc.addedEffect) {
994+
const envButtonRect: DOMRect = this._addEnvelopeButton.getBoundingClientRect();
995+
const instSettingsRect: DOMRect = this._instrumentSettingsArea.getBoundingClientRect();
996+
const settingsRect: DOMRect = this._settingsArea.getBoundingClientRect();
997+
this._instrumentSettingsArea.scrollTop += Math.max(0, envButtonRect.top - (instSettingsRect.top + instSettingsRect.height));
998+
this._settingsArea.scrollTop += Math.max(0, envButtonRect.top - (settingsRect.top + settingsRect.height));
999+
this._doc.addedEffect = false;
1000+
}
1001+
if (this._doc.addedEnvelope) {
1002+
this._instrumentSettingsArea.scrollTop = this._instrumentSettingsArea.scrollHeight;
1003+
this._settingsArea.scrollTop = this._settingsArea.scrollHeight;
1004+
this._doc.addedEnvelope = false;
1005+
}
9911006
}
9921007

9931008
public updatePlayButton(): void {
@@ -1435,9 +1450,14 @@ export class SongEditor {
14351450
}
14361451

14371452
private _whenSetEffects = (): void => {
1453+
const instrument: Instrument = this._doc.song.channels[this._doc.channel].instruments[this._doc.getCurrentInstrument()];
1454+
const oldValue: number = instrument.effects;
14381455
const toggleFlag: number = Config.effectOrder[this._effectsSelect.selectedIndex - 1];
14391456
this._doc.record(new ChangeToggleEffects(this._doc, toggleFlag));
14401457
this._effectsSelect.selectedIndex = 0;
1458+
if (instrument.effects > oldValue) {
1459+
this._doc.addedEffect = true;
1460+
}
14411461
}
14421462

14431463
private _whenSetVibrato = (): void => {
@@ -1455,6 +1475,7 @@ export class SongEditor {
14551475
private _addNewEnvelope = (): void => {
14561476
this._doc.record(new ChangeAddEnvelope(this._doc));
14571477
this._refocusStage();
1478+
this._doc.addedEnvelope = true;
14581479
}
14591480

14601481
private _zoomIn = (): void => {

0 commit comments

Comments
 (0)