Skip to content

Commit

Permalink
Merge pull request #549 from tfriedel/convert_windows_path_to_wsl
Browse files Browse the repository at this point in the history
Convert Windows paths to WSL paths when running under WSL
  • Loading branch information
akiyosi authored Aug 16, 2024
2 parents 443a6ed + 3b0c602 commit 8e5d65b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions editor/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -3473,6 +3473,11 @@ func (w *Window) dropEvent(e *gui.QDropEvent) {
}
}

// Check if running under WSL and convert path if necessary
if editor.opts.Wsl != nil {
filepath = convertWindowsToUnixPath(filepath)
}

// if message grid is active and drop the file in message area,
// then, we put the filepath string into message area.
if w.isMsgGrid && w.s.ws.cursor.gridid == w.grid {
Expand Down Expand Up @@ -3510,6 +3515,20 @@ func (w *Window) focusGrid() {
}
}

// convertWindowsToUnixPath converts a Windows path to a Unix path as wslpath does.
func convertWindowsToUnixPath(winPath string) string {
unixPath := strings.ReplaceAll(winPath, `\`, `/`)
if len(unixPath) <= 2 {
return unixPath
}
// Convert drive letter to /mnt/<drive-letter>
if unixPath[1] == ':' {
driveLetter := strings.ToLower(string(unixPath[0]))
unixPath = fmt.Sprintf("/mnt/%s%s", driveLetter, unixPath[2:])
}
return unixPath
}

func (w *Window) isShown() bool {
if w == nil {
return false
Expand Down

0 comments on commit 8e5d65b

Please sign in to comment.