Skip to content

Commit

Permalink
Refactored focus behavior, added code editor settings, debug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
StanZGenchev committed Dec 17, 2024
1 parent dfeb2d8 commit 9bcbaa1
Show file tree
Hide file tree
Showing 15 changed files with 395 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@
const layoutHub = new LayoutHub();
const statusBarHub = new StatusBarHub();
var editorParams;
const tabId = window.frameElement?.getAttribute('tab-id');
window.addEventListener('focus', () => {
layoutHub.focusEditor({
id: tabId,
path: editorParams.filePath,
});
});

if (window.frameElement && window.frameElement.hasAttribute("data-parameters")) {
editorParams = JSON.parse(window.frameElement.getAttribute("data-parameters") || '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ flowableModeler

updateWindowSize();

layout.onReloadEditorParams((data) => {
layoutHub.onReloadEditorParams((data) => {
if (editorParams.filePath === data.path) {
if ($window.frameElement && $window.frameElement.hasAttribute("data-parameters")) {
editorParams = JSON.parse($window.frameElement.getAttribute("data-parameters"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ editorView.controller('ImageViewController', function ($scope, $window, Workspac
$scope.state.isBusy = false;
};

layoutHub.onFocusView((data) => {
if (data.params && data.params.resourcePath === $scope.dataParameters.filePath) statusBarHub.showLabel('');
layoutHub.onFocusEditor((data) => {
if (data.path && data.path === $scope.dataParameters.filePath) statusBarHub.showLabel('');
});

layoutHub.onReloadEditorParams((data) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ function getViewParameters() {
}

let editorParameters = getViewParameters();
const tabId = window.frameElement?.getAttribute('tab-id');

window.addEventListener('focus', () => {
layoutHub.focusEditor({
id: tabId,
path: editorParameters.resourcePath,
});
});

// @ts-ignore
require.config({
Expand Down Expand Up @@ -396,11 +404,6 @@ class EditorActionsProvider {
static #autoFormatExcludedKey = `${brandingInfo.keyPrefix}.code-editor.autoFormat.excluded`;
static _toggleAutoFormattingActionRegistration = undefined;

static isAutoRevealEnabled() {
const autoRevealEnabled = window.localStorage.getItem(`${brandingInfo.keyPrefix}.code-editor.autoReveal`);
return autoRevealEnabled === null || autoRevealEnabled === 'true';
}

static isAutoFormattingEnabled() {
const autoFormat = window.localStorage.getItem(`${brandingInfo.keyPrefix}.code-editor.autoFormat`);
return autoFormat === null || autoFormat === 'true';
Expand Down Expand Up @@ -516,6 +519,26 @@ class DirigibleEditor {
static sourceBeingChangedProgramatically = false;
static computeDiff = new Worker("js/workers/computeDiff.js");

static isAutoBracketsEnabled() {
const autoBracketsEnabled = window.localStorage.getItem(`${brandingInfo.keyPrefix}.code-editor.autoBrackets`);
return autoBracketsEnabled === null || autoBracketsEnabled === 'true';
}

static isMinimapAutohideEnabled() {
const minimapAutohideEnabled = window.localStorage.getItem(`${brandingInfo.keyPrefix}.code-editor.minimapAutohide`);
return minimapAutohideEnabled === null || minimapAutohideEnabled === 'true';
}

static getRenderWhitespace() {
const whitespace = window.localStorage.getItem(`${brandingInfo.keyPrefix}.code-editor.whitespace`);
return whitespace ?? 'trailing';
}

static getWordWrap() {
const wordWrap = window.localStorage.getItem(`${brandingInfo.keyPrefix}.code-editor.wordWrap`);
return wordWrap ?? 'off';
}

static closeEditor() {
layoutHub.closeEditor({
path: editorParameters.resourcePath,
Expand Down Expand Up @@ -548,9 +571,7 @@ class DirigibleEditor {
}

async init() {
if (!this.fileName) {
return
}
if (!this.fileName) return;

this.editor = await this.#createEditorInstance();

Expand Down Expand Up @@ -587,6 +608,12 @@ class DirigibleEditor {
value: '',
automaticLayout: true,
readOnly: readOnly,
autoClosingBrackets: DirigibleEditor.isAutoBracketsEnabled(),
renderWhitespace: DirigibleEditor.getRenderWhitespace(),
wordWrap: DirigibleEditor.getWordWrap(),
minimap: {
autohide: DirigibleEditor.isMinimapAutohideEnabled(),
}
};
if (TypeScriptUtils.isTypeScriptFile(fileName)) {
// @ts-ignore
Expand Down Expand Up @@ -665,22 +692,6 @@ class DirigibleEditor {
}
});

editor.onDidFocusEditorText(function () {
layoutHub.openEditor({
path: editorParameters.resourcePath,
});
if (EditorActionsProvider.isAutoRevealEnabled()) {
setTimeout(() => {
themingHub.postMessage({
topic: 'projects.tree.select',
data: {
filePath: editorParameters.resourcePath
}
});
}, 100);
}
});

editor.onDidChangeCursorPosition(function (e) {
statusBarHub.showLabel(`Line ${e.position.lineNumber}, Column ${e.position.column}`);
});
Expand All @@ -691,15 +702,6 @@ class DirigibleEditor {
editor.addAction(EditorActionsProvider.createSearchAction());
if (!this.isTemplate) {
EditorActionsProvider._toggleAutoFormattingActionRegistration = editor.addAction(EditorActionsProvider.createToggleAutoFormattingAction());
themingHub.addMessageListener({
topic: 'code-editor.settings.update', handler: (data) => {
if (data.fileName && data.fileName === fileName && EditorActionsProvider._toggleAutoFormattingActionRegistration) {
// @ts-ignore
EditorActionsProvider._toggleAutoFormattingActionRegistration.dispose();
EditorActionsProvider._toggleAutoFormattingActionRegistration = editor.addAction(EditorActionsProvider.createToggleAutoFormattingAction());
}
}
});
}

DirigibleEditor.computeDiff.onmessage = function (event) {
Expand Down Expand Up @@ -847,10 +849,6 @@ class DirigibleEditor {
}
});

themingHub.onThemeChange((theme) => {
setTheme(theme, this.monaco);
});

const getTypeScriptFileImport = (model, position, fileObject) => {
const lineContent = model.getLineContent(position.lineNumber);
for (const next of fileObject.importedFilesNames) {
Expand Down Expand Up @@ -888,10 +886,35 @@ class DirigibleEditor {

subscribeEvents() {
const fileIO = new FileIO();
const fileName = this.fileName;
const editor = this.editor;
const monaco = this.monaco;
const fileObject = this.fileObject;

themingHub.addMessageListener({
topic: 'code-editor.settings.update', handler: (data) => {
if (data.setting === 'autoFormat' && !this.isTemplate) {
if (data.fileName && data.fileName === fileName && EditorActionsProvider._toggleAutoFormattingActionRegistration) {
// @ts-ignore
EditorActionsProvider._toggleAutoFormattingActionRegistration.dispose();
EditorActionsProvider._toggleAutoFormattingActionRegistration = editor.addAction(EditorActionsProvider.createToggleAutoFormattingAction());
}
} else if (data.setting === 'autoBrackets') {
editor.updateOptions({ autoClosingBrackets: data.value });
} else if (data.setting === 'minimapAutohide') {
editor.updateOptions({ minimap: { autohide: data.value } });
} else if (data.setting === 'whitespace') {
editor.updateOptions({ renderWhitespace: data.value });
} else if (data.setting === 'wordWrap') {
editor.updateOptions({ wordWrap: data.value });
}
}
});

themingHub.onThemeChange((theme) => {
setTheme(theme, this.monaco);
});

workspaceHub.onSaveFile(async function (data) {
if (data.file && data.file === fileIO.resolveResourcePath()) {
const model = editor.getModel();
Expand Down Expand Up @@ -919,16 +942,8 @@ class DirigibleEditor {
}
});

layoutHub.onFocusView((data) => {
if (data.params && data.params.file === fileIO.resolveResourcePath()) {
editor.focus();
if (EditorActionsProvider.isAutoRevealEnabled()) {
themingHub.postMessage({
topic: 'projects.tree.select',
data: { filePath: data.id }
});
}
}
layoutHub.onFocusEditor((data) => {
if (data.path === fileIO.resolveResourcePath()) editor.focus();
});

themingHub.addMessageListener({
Expand Down
Loading

0 comments on commit 9bcbaa1

Please sign in to comment.