mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 09:38:38 +01:00
Getting closer to shared config #59803
This commit is contained in:
@@ -35,7 +35,7 @@ export function updateImageSize() {
|
||||
return Promise.all(allUpdatesPromise).then((updates) => {
|
||||
return editor.edit(builder => {
|
||||
updates.forEach(update => {
|
||||
update!.forEach((textEdit: TextEdit) => {
|
||||
update.forEach((textEdit: TextEdit) => {
|
||||
builder.replace(textEdit.range, textEdit.newText);
|
||||
});
|
||||
});
|
||||
@@ -46,7 +46,7 @@ export function updateImageSize() {
|
||||
/**
|
||||
* Updates image size of context tag of HTML model
|
||||
*/
|
||||
function updateImageSizeHTML(editor: TextEditor, position: Position): Promise<TextEdit[] | undefined> {
|
||||
function updateImageSizeHTML(editor: TextEditor, position: Position): Promise<TextEdit[]> {
|
||||
const imageNode = getImageHTMLNode(editor, position);
|
||||
|
||||
const src = imageNode && getImageSrcHTML(imageNode);
|
||||
@@ -64,11 +64,12 @@ function updateImageSizeHTML(editor: TextEditor, position: Position): Promise<Te
|
||||
if (img && getImageSrcHTML(img) === src) {
|
||||
return updateHTMLTag(editor, img, size.width, size.height);
|
||||
}
|
||||
return [];
|
||||
})
|
||||
.catch(err => { console.warn('Error while updating image size:', err); return []; });
|
||||
}
|
||||
|
||||
function updateImageSizeStyleTag(editor: TextEditor, position: Position): Promise<TextEdit[] | undefined> {
|
||||
function updateImageSizeStyleTag(editor: TextEditor, position: Position): Promise<TextEdit[]> {
|
||||
const getPropertyInsiderStyleTag = (editor: TextEditor): Property | null => {
|
||||
const rootNode = parseDocument(editor.document);
|
||||
const currentNode = <HtmlNode>getNode(rootNode, position, true);
|
||||
@@ -86,14 +87,14 @@ function updateImageSizeStyleTag(editor: TextEditor, position: Position): Promis
|
||||
return updateImageSizeCSS(editor, position, getPropertyInsiderStyleTag);
|
||||
}
|
||||
|
||||
function updateImageSizeCSSFile(editor: TextEditor, position: Position): Promise<TextEdit[] | undefined> {
|
||||
function updateImageSizeCSSFile(editor: TextEditor, position: Position): Promise<TextEdit[]> {
|
||||
return updateImageSizeCSS(editor, position, getImageCSSNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates image size of context rule of stylesheet model
|
||||
*/
|
||||
function updateImageSizeCSS(editor: TextEditor, position: Position, fetchNode: (editor: TextEditor, position: Position) => Property | null): Promise<TextEdit[] | undefined> {
|
||||
function updateImageSizeCSS(editor: TextEditor, position: Position, fetchNode: (editor: TextEditor, position: Position) => Property | null): Promise<TextEdit[]> {
|
||||
const node = fetchNode(editor, position);
|
||||
const src = node && getImageSrcCSS(node, position);
|
||||
|
||||
@@ -103,13 +104,14 @@ function updateImageSizeCSS(editor: TextEditor, position: Position, fetchNode: (
|
||||
|
||||
return locateFile(path.dirname(editor.document.fileName), src)
|
||||
.then(getImageSize)
|
||||
.then((size: any): TextEdit[] | undefined => {
|
||||
.then((size: any): TextEdit[] => {
|
||||
// since this action is asynchronous, we have to ensure that editor wasn’t
|
||||
// changed and user didn’t moved caret outside <img> node
|
||||
const prop = fetchNode(editor, position);
|
||||
if (prop && getImageSrcCSS(prop, position) === src) {
|
||||
return updateCSSNode(editor, prop, size.width, size.height);
|
||||
}
|
||||
return [];
|
||||
})
|
||||
.catch(err => { console.warn('Error while updating image size:', err); return []; });
|
||||
}
|
||||
@@ -261,12 +263,14 @@ function findUrlToken(node: Property, pos: Position): CssToken | undefined {
|
||||
url = token;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if (url) {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user