Skip to content

Commit a5546b9

Browse files
committed
feat: add setting to show image preview (#188)
Co-Authored-By: Tony Brix <[email protected]>
1 parent 0410d2f commit a5546b9

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/config/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export const config = {
2222
default: false,
2323
description: "Follow directory symlinks. Disable if you have a self-referencing symlink.",
2424
},
25+
imagePreview: {
26+
type: "boolean",
27+
default: false,
28+
description: "Show preview icon for images.",
29+
},
2530
ignoredNames: {
2631
type: "boolean",
2732
default: true,

lib/paths-provider.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,13 @@ export default class PathsProvider extends EventEmitter {
103103
})
104104
}
105105

106+
const showImagePreview = atom.config.get("autocomplete-paths.imagePreview")
107+
const imgRegex = /\.(png|svg|jpg|jpeg|jfif|pjpeg|pjp|gif|apng|ico|cur)$/
108+
106109
const suggestions = files.map((pathName) => {
107110
let text = pathName
108111
const normalizeSlashes = atom.config.get("autocomplete-paths.normalizeSlashes")
109-
112+
const absolutePath = path.resolve(path.dirname(request.editor.getPath()), pathName)
110113
const projectRelativePath = atom.project.relativizePath(text)[1]
111114
let displayText = projectRelativePath
112115
if (directoryGiven) {
@@ -147,12 +150,17 @@ export default class PathsProvider extends EventEmitter {
147150

148151
// Calculate distance to file
149152
const distanceToFile = relativePath.split(path.sep).length
153+
154+
const iconHTML =
155+
showImagePreview && imgRegex.test(absolutePath)
156+
? `<image style="background-position: center; background-repeat: no-repeat; background-size: contain; background-image: url(${absolutePath}); height:29px; width:29px;"></image>`
157+
: '<i class="icon-file-code"></i>'
150158
return {
151159
text,
152160
replacementPrefix: pathPrefix,
153161
displayText,
154162
type: "import",
155-
iconHTML: '<i class="icon-file-code"></i>',
163+
iconHTML,
156164
score: score(displayText, request.prefix),
157165
distanceToFile,
158166
}

0 commit comments

Comments
 (0)