Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: wrong type of paste event and missing types for themelist extension #5725

Merged
merged 5 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ace-internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ export namespace Ace {
/**
* Emitted when text is pasted.
**/
"paste": (text: string, event: any) => void;
"paste": (e: { text: string, event?: ClipboardEvent }) => void;
/**
* Emitted when the selection style changes, via [[Editor.setSelectionStyle]].
* @param data Contains one property, `data`, which indicates the new selection style
Expand All @@ -530,6 +530,7 @@ export namespace Ace {
"gutterclick": (e: MouseEvent) => void;
"showGutterTooltip": (e: GutterTooltip) => void;
"hideGutterTooltip": (e: GutterTooltip) => void;
"compositionStart": () => void;
}

interface AcePopupEvents {
Expand Down Expand Up @@ -1334,6 +1335,7 @@ declare module "./src/editor" {
showSettingsMenu?: () => void,
searchBox?: Ace.SearchBox,
_eventRegistry?: any,
$textInputAriaLabel?: string
}
}

Expand Down
6 changes: 5 additions & 1 deletion ace.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,10 @@ declare module "ace-code" {
/**
* Emitted when text is pasted.
**/
"paste": (text: string, event: any) => void;
"paste": (e: {
text: string;
event?: ClipboardEvent;
}) => void;
/**
* Emitted when the selection style changes, via [[Editor.setSelectionStyle]].
* @param data Contains one property, `data`, which indicates the new selection style
Expand All @@ -443,6 +446,7 @@ declare module "ace-code" {
"gutterclick": (e: MouseEvent) => void;
"showGutterTooltip": (e: GutterTooltip) => void;
"hideGutterTooltip": (e: GutterTooltip) => void;
"compositionStart": () => void;
}
interface AcePopupEvents {
"click": (e: MouseEvent) => void;
Expand Down
12 changes: 11 additions & 1 deletion demo/test_package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {MarkerGroup, MarkerGroupItem} from "ace-code/src/marker_group";
import {HoverTooltip} from "ace-code/src/tooltip";
import {hardWrap} from "ace-code/src/ext/hardwrap";
import {SearchBox} from "ace-code/src/ext/searchbox";
import {themesByName} from 'ace-code/src/ext/themelist';

import("ace-code/src/ext/language_tools");
import "../../src/test/mockdom.js";
Expand Down Expand Up @@ -134,4 +135,13 @@ const filter = new FilteredList([]);
filter.setFilter("test");

editor.session.startOperation();
editor.session.endOperation();
editor.session.endOperation();

editor.on("paste", (e) => {
var htmlString = e.event?.clipboardData?.getData("text/html")
if (htmlString) {
e.text = htmlString
}
})

themesByName.textmate?.theme;
4 changes: 2 additions & 2 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ class Editor {
/**
* Called whenever a text "paste" happens.
* @param {String} text The pasted text
* @param {any} event
* @param {ClipboardEvent} [event]
* @internal
**/
onPaste(text, event) {
Expand All @@ -863,7 +863,7 @@ class Editor {

/**
*
* @param e
* @param {string | {text: string, event?: ClipboardEvent}} e
* @returns {boolean}
*/
$handlePaste(e) {
Expand Down
13 changes: 12 additions & 1 deletion src/ext/themelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@

"use strict";

/**
* @typedef {Object} Theme
* @property {string} caption - The display caption of the theme.
* @property {string} theme - The path or identifier for the ACE theme.
* @property {boolean} isDark - Indicates whether the theme is dark or light.
* @property {string} name - The normalized name used as the key.
*/

var themeData = [
["Chrome" ],
["Clouds" ],
Expand Down Expand Up @@ -54,11 +62,14 @@ var themeData = [
["CloudEditor Dark" ,"cloud_editor_dark" , "dark"]
];


/**
* @type {Object<string, Theme>}
*/
exports.themesByName = {};

/**
* An array containing information about available themes.
* @type {Theme[]}
*/
exports.themes = themeData.map(function(data) {
var name = data[1] || data[0].replace(/ /g, "_").toLowerCase();
Expand Down
8 changes: 4 additions & 4 deletions src/keyboard/textinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var valueResetRegex = isIOS ? /\s/ : /\n/;
var isMobile = useragent.isMobile;

var TextInput;
TextInput= function(parentNode, host) {
TextInput= function(/**@type{HTMLTextAreaElement} */parentNode, /**@type{import("../editor").Editor} */host) {
/**@type {HTMLTextAreaElement & {msGetInputContext?: () => {compositionStartOffset: number}, getInputContext?: () => {compositionStartOffset: number}}}*/
var text = dom.createElement("textarea");
text.className = "ace_text-input";
Expand All @@ -35,7 +35,7 @@ TextInput= function(parentNode, host) {
text.style.opacity = "0";
parentNode.insertBefore(text, parentNode.firstChild);

var copied = false;
/**@type{boolean|string}*/var copied = false;
var pasted = false;
/**@type {(boolean|Object) & {context?: any, useTextareaForIME?: boolean, selectionStart?: number, markerRange?: any}}} */
var inComposition = false;
Expand All @@ -62,7 +62,7 @@ TextInput= function(parentNode, host) {

// Set number of extra lines in textarea, some screenreaders
// perform better with extra lines above and below in the textarea.
this.setNumberOfExtraLines = function(number) {
this.setNumberOfExtraLines = function(/**@type{number}*/number) {
rowStart = Number.MAX_SAFE_INTEGER;
rowEnd = Number.MIN_SAFE_INTEGER;

Expand Down Expand Up @@ -695,7 +695,7 @@ TextInput= function(parentNode, host) {
var rect = host.container.getBoundingClientRect();
var style = dom.computedStyle(host.container);
var top = rect.top + (parseInt(style.borderTopWidth) || 0);
var left = rect.left + (parseInt(rect.borderLeftWidth) || 0);
var left = rect.left + (parseInt(style.borderLeftWidth) || 0);
var maxTop = rect.bottom - top - text.clientHeight -2;
var move = function(e) {
dom.translate(text, e.clientX - left - 2, Math.min(e.clientY - top - 2, maxTop));
Expand Down
21 changes: 18 additions & 3 deletions types/ace-ext.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,28 @@ declare module "ace-code/src/ext/modelist" {
}
}
declare module "ace-code/src/ext/themelist" {
export const themesByName: {};
export const themes: {
export const themesByName: {
[x: string]: Theme;
};
export const themes: Theme[];
export type Theme = {
/**
* - The display caption of the theme.
*/
caption: string;
/**
* - The path or identifier for the ACE theme.
*/
theme: string;
/**
* - Indicates whether the theme is dark or light.
*/
isDark: boolean;
/**
* - The normalized name used as the key.
*/
name: string;
}[];
};
}
declare module "ace-code/src/ext/options" {
export class OptionPanel {
Expand Down
Loading