aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/src/editors/ui/webview-ui/main.ts
blob: 9db7dc4225531ac520323a345c8325d2a3f96d4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only

import {
  provideVSCodeDesignSystem,
  vsCodeButton
} from '@vscode/webview-ui-toolkit';

declare function acquireVsCodeApi(): { postMessage(message: unknown): void };

provideVSCodeDesignSystem().register(vsCodeButton());

const vscode = acquireVsCodeApi();

window.addEventListener('load', main);

function main() {
  const openWithDesignerButton = document.getElementById(
    'openWithDesignerButton'
  );
  if (openWithDesignerButton) {
    openWithDesignerButton.focus();
  }
  function onOpenWithDesignerButtonClick() {
    vscode.postMessage({
      type: 'run'
    });
  }
  openWithDesignerButton?.addEventListener(
    'click',
    onOpenWithDesignerButtonClick
  );

  openWithDesignerButton?.addEventListener('keydown', function (event) {
    if (event.key === 'Enter') {
      event.preventDefault();
      onOpenWithDesignerButtonClick();
    }
  });
  document.addEventListener('keydown', function (event) {
    // if any arrow key is pressed, focus the this button
    if (
      event.key === 'ArrowUp' ||
      event.key === 'ArrowDown' ||
      event.key === 'ArrowLeft' ||
      event.key === 'ArrowRight'
    ) {
      event.preventDefault();
      openWithDesignerButton?.focus();
    }
  });
}