File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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 = / \. ( p n g | s v g | j p g | j p e g | j f i f | p j p e g | p j p | g i f | a p n g | i c o | c u r ) $ /
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 }
You can’t perform that action at this time.
0 commit comments