Some tweaks, directory viewing
This commit is contained in:
parent
030f0e6438
commit
4648240842
@ -6,15 +6,21 @@ const handleNeutralinoError = err => {
|
|||||||
throw new Error(err.code + ': ' + err.message)
|
throw new Error(err.code + ': ' + err.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mapDirent = ({ entry, type }) => ({
|
||||||
|
name: entry,
|
||||||
|
type
|
||||||
|
})
|
||||||
|
|
||||||
window.Platform = {
|
window.Platform = {
|
||||||
//
|
//
|
||||||
// Paths
|
// Paths
|
||||||
//
|
//
|
||||||
|
|
||||||
dirname(path) {
|
dirname(path) {
|
||||||
let index = path.lastIndexOf('/')
|
let normalPath = this.normalize(path)
|
||||||
|
let index = normalPath.lastIndexOf('/')
|
||||||
|
|
||||||
return index === -1 ? '' : path.slice(0, index)
|
return index === -1 ? '' : normalPath.slice(0, index)
|
||||||
},
|
},
|
||||||
|
|
||||||
filename(path) {
|
filename(path) {
|
||||||
@ -31,7 +37,13 @@ window.Platform = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
join(...args) {
|
join(...args) {
|
||||||
return args.join('/')
|
let parts = []
|
||||||
|
|
||||||
|
for(let arg of args) {
|
||||||
|
parts = parts.concat(arg.split('/'))
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.normalizePathFromParts(parts)
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO: support non-posix
|
// TODO: support non-posix
|
||||||
@ -39,6 +51,38 @@ window.Platform = {
|
|||||||
return path.charAt(0) === '/'
|
return path.charAt(0) === '/'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
normalize(path) {
|
||||||
|
return this.normalizePathFromParts(path.split('/'))
|
||||||
|
},
|
||||||
|
|
||||||
|
normalizePathFromParts(parts) {
|
||||||
|
// let newPath = path !== '/' && path.endsWith('/') ?
|
||||||
|
// path.slice(0, -1) :
|
||||||
|
// path
|
||||||
|
|
||||||
|
let out = []
|
||||||
|
let skips = 0
|
||||||
|
|
||||||
|
for(let i = parts.length - 1; i >= 0; i--) {
|
||||||
|
let part = parts[i]
|
||||||
|
|
||||||
|
if(part.length == 0 || part === '.') {
|
||||||
|
continue
|
||||||
|
} else if(part == '..') {
|
||||||
|
skips++
|
||||||
|
continue
|
||||||
|
} else if(skips == 0) {
|
||||||
|
out.unshift(part)
|
||||||
|
} else {
|
||||||
|
skips--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(out)
|
||||||
|
|
||||||
|
return '/' + out.join('/')
|
||||||
|
},
|
||||||
|
|
||||||
//
|
//
|
||||||
// FS
|
// FS
|
||||||
//
|
//
|
||||||
@ -66,6 +110,12 @@ window.Platform = {
|
|||||||
.catch(handleNeutralinoError)
|
.catch(handleNeutralinoError)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
readdir(path) {
|
||||||
|
return Neutralino.filesystem.readDirectory(path)
|
||||||
|
.catch(handleNeutralinoError)
|
||||||
|
.then(dirents => dirents.map(mapDirent))
|
||||||
|
},
|
||||||
|
|
||||||
//
|
//
|
||||||
// OS
|
// OS
|
||||||
//
|
//
|
||||||
|
5
notes.md
5
notes.md
@ -3,6 +3,11 @@
|
|||||||
Needed to
|
Needed to
|
||||||
```sudo apt install libsoup-2.4-dev libwebkit2gtk-4.0-dev libjavascriptcoregtk-4.0-dev```
|
```sudo apt install libsoup-2.4-dev libwebkit2gtk-4.0-dev libjavascriptcoregtk-4.0-dev```
|
||||||
|
|
||||||
|
On void:
|
||||||
|
```
|
||||||
|
sudo xbps-install webkit2gtk-devel
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
# Functionality
|
# Functionality
|
||||||
|
@ -15,7 +15,8 @@
|
|||||||
"build-deps": "cd lib && rollup -c",
|
"build-deps": "cd lib && rollup -c",
|
||||||
"dev": "neu run",
|
"dev": "neu run",
|
||||||
"build": "neu build",
|
"build": "neu build",
|
||||||
"update": "neu update"
|
"update": "neu update",
|
||||||
|
"install:neu": "rm src/lib/platform.js && ln lib/platforms/neutralino.js src/lib/platforms.js && ln build/neutralino.js src/lib/neutralino.js"
|
||||||
},
|
},
|
||||||
"type": "module"
|
"type": "module"
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,8 @@ binds: {
|
|||||||
reload: 'Ctrl-Escape',
|
reload: 'Ctrl-Escape',
|
||||||
editPath: 'Ctrl-r',
|
editPath: 'Ctrl-r',
|
||||||
save: 'Ctrl-s',
|
save: 'Ctrl-s',
|
||||||
open: 'Ctrl-o'
|
open: 'Ctrl-o',
|
||||||
|
openDirectory: 'Ctrl-l'
|
||||||
},
|
},
|
||||||
|
|
||||||
languages: [
|
languages: [
|
||||||
|
80
src/qwe.js
80
src/qwe.js
@ -25,16 +25,10 @@ function Editor() {
|
|||||||
this.view.focus()
|
this.view.focus()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Opens a directory or a file
|
|
||||||
this.open = path => {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
this.openDocument = async (path) => {
|
this.openDocument = async (path) => {
|
||||||
this.doc = await Doc.open(path)
|
await Doc.open(path)
|
||||||
.catch(err => `Failed to open "${path}": ${err}`)
|
.then(doc => this.setDoc(doc))
|
||||||
this.view.setState(await this.doc.createState())
|
.catch(err => console.error(`Failed to open "${path}": ${err}`))
|
||||||
this.doc.setView(this.view)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.saveDocument = () => {
|
this.saveDocument = () => {
|
||||||
@ -51,6 +45,23 @@ function Editor() {
|
|||||||
statusbar.updateFilename()
|
statusbar.updateFilename()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.setDoc = async (doc, bind) => {
|
||||||
|
this.doc = doc
|
||||||
|
statusbar.updateFilename()
|
||||||
|
this.view.setState(await this.doc.createState())
|
||||||
|
this.doc.setView(this.view)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.openDirectory = async (path) => {
|
||||||
|
let fileList = (await Platform.readdir(path))
|
||||||
|
.filter(dirent => dirent.name != '.')
|
||||||
|
.map(dirent => dirent.type == 'FILE' ? dirent.name : dirent.name + '/')
|
||||||
|
.join('\n')
|
||||||
|
|
||||||
|
let doc = new Doc(fileList, Platform.join(path, '~' + Platform.filename(path)))
|
||||||
|
editor.setDoc(doc)
|
||||||
|
}
|
||||||
|
|
||||||
// this.updateFilename = () => {
|
// this.updateFilename = () => {
|
||||||
// this.doc.path = Platform.dirname(this.doc.path) + '/' + statusbar.filename.value
|
// this.doc.path = Platform.dirname(this.doc.path) + '/' + statusbar.filename.value
|
||||||
// }
|
// }
|
||||||
@ -79,11 +90,11 @@ function Statusbar() {
|
|||||||
|
|
||||||
this.filename.value = path
|
this.filename.value = path
|
||||||
this.filename.select()
|
this.filename.select()
|
||||||
this.filename.selectionStart = path.length - Platform.filename(path).length
|
this.filename.selectionStart = path.length - getPathName(path).length
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateFilename = () => {
|
this.updateFilename = () => {
|
||||||
this.filename.value = Platform.filename(editor.doc.getPath())
|
this.filename.value = getPathName(editor.doc.getPath())
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateWorkspace = () => {
|
this.updateWorkspace = () => {
|
||||||
@ -109,6 +120,16 @@ function Statusbar() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getPathName = path => {
|
||||||
|
if(path.endsWith('/')) {
|
||||||
|
let index = path.lastIndexOf('/', path.length - 2) + 1
|
||||||
|
|
||||||
|
return path.slice(index)
|
||||||
|
} else {
|
||||||
|
return Platform.filename(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.element = document.createElement('nav')
|
this.element = document.createElement('nav')
|
||||||
this.filename = document.createElement('input')
|
this.filename = document.createElement('input')
|
||||||
this.workspace = document.createElement('input')
|
this.workspace = document.createElement('input')
|
||||||
@ -150,6 +171,7 @@ function Doc(content, initialPath) {
|
|||||||
cm.rectangularSelection(),
|
cm.rectangularSelection(),
|
||||||
cm.crosshairCursor(),
|
cm.crosshairCursor(),
|
||||||
cm.highlightSelectionMatches(),
|
cm.highlightSelectionMatches(),
|
||||||
|
cm.history(),
|
||||||
Keymaps.default
|
Keymaps.default
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -217,13 +239,9 @@ function Doc(content, initialPath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Doc.open = async (path) => {
|
Doc.open = async (path) => {
|
||||||
console.log('Opening ' + path)
|
|
||||||
|
|
||||||
let content = await Platform.readText(path)
|
let content = await Platform.readText(path)
|
||||||
.catch(console.error)
|
.catch(console.error)
|
||||||
|
|
||||||
console.log(content)
|
|
||||||
|
|
||||||
return new Doc(content ?? '', path)
|
return new Doc(content ?? '', path)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,6 +256,7 @@ const Keymaps = {
|
|||||||
...cm.searchKeymap,
|
...cm.searchKeymap,
|
||||||
...cm.foldKeymap,
|
...cm.foldKeymap,
|
||||||
...cm.lintKeymap,
|
...cm.lintKeymap,
|
||||||
|
...cm.historyKeymap,
|
||||||
|
|
||||||
// Alt completion keymap that merges with tab to indent
|
// Alt completion keymap that merges with tab to indent
|
||||||
{ key: "Ctrl-Space", run: cm.startCompletion },
|
{ key: "Ctrl-Space", run: cm.startCompletion },
|
||||||
@ -266,8 +285,7 @@ const Keymaps = {
|
|||||||
|
|
||||||
if(!mainSelection.empty) {
|
if(!mainSelection.empty) {
|
||||||
let path = state.sliceDoc(mainSelection.from, mainSelection.to).trim()
|
let path = state.sliceDoc(mainSelection.from, mainSelection.to).trim()
|
||||||
|
let isDirectory = path.endsWith('/')
|
||||||
console.log(path)
|
|
||||||
|
|
||||||
editor.setDocPath(
|
editor.setDocPath(
|
||||||
Platform.absolute(path) ?
|
Platform.absolute(path) ?
|
||||||
@ -275,10 +293,18 @@ const Keymaps = {
|
|||||||
Platform.join(Platform.dirname(editor.doc.getPath()), path)
|
Platform.join(Platform.dirname(editor.doc.getPath()), path)
|
||||||
)
|
)
|
||||||
|
|
||||||
statusbar.updateFilename()
|
path = editor.doc.getPath()
|
||||||
|
|
||||||
|
if(isDirectory) {
|
||||||
|
editor.openDirectory(path)
|
||||||
|
} else {
|
||||||
|
editor.openDocument(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.openDocument(editor.doc.getPath())
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
editor.openDirectory(editor.doc.getPath())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -287,6 +313,22 @@ const Keymaps = {
|
|||||||
editor.saveDocument()
|
editor.saveDocument()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: config.binds.openDirectory,
|
||||||
|
async run() {
|
||||||
|
let path = editor.doc.getPath()
|
||||||
|
|
||||||
|
if(Platform.filename(path).startsWith('~'))
|
||||||
|
path = Platform.join(path, '../../')
|
||||||
|
else
|
||||||
|
path = Platform.dirname(path)
|
||||||
|
// path = path.endsWith('/') ? path.slice(0, -1) : path
|
||||||
|
|
||||||
|
console.log(path)
|
||||||
|
|
||||||
|
editor.openDirectory(path)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
key: config.binds.reload,
|
key: config.binds.reload,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user