Compare commits
5
Commits
ba97003ea0
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2bcbea074e | ||
|
|
b6673c6420 | ||
|
|
6c5a45e195 | ||
|
|
1b3e29e4f6 | ||
|
|
867405fae2 |
@@ -326,10 +326,10 @@ jobs:
|
|||||||
echo "value=$TAGS" >> $GITHUB_OUTPUT
|
echo "value=$TAGS" >> $GITHUB_OUTPUT
|
||||||
echo "build_version=$BUILD_VERSION" >> $GITHUB_OUTPUT
|
echo "build_version=$BUILD_VERSION" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
# No disk-space prune step: the runner's Docker daemon is shared, and
|
- name: Free disk space
|
||||||
# `docker system prune -af` here deleted images other repos' jobs had
|
run: |
|
||||||
# just pulled and were about to start (CI-runner #16). The runner host
|
docker system prune -af || true
|
||||||
# prunes nightly instead.
|
docker builder prune --keep-storage 5g -f || true
|
||||||
|
|
||||||
# Bake EVERY client in, on every image build, so a self-hoster gets a working
|
# Bake EVERY client in, on every image build, so a self-hoster gets a working
|
||||||
# app for their machine from the server holding their notes, with no trip to a
|
# app for their machine from the server holding their notes, with no trip to a
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
package com.fabledsword.inkwell.ui
|
package com.fabledsword.inkwell.ui
|
||||||
|
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.compose.foundation.horizontalScroll
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.rememberScrollState
|
|
||||||
import androidx.compose.foundation.text.BasicTextField
|
import androidx.compose.foundation.text.BasicTextField
|
||||||
import androidx.compose.foundation.text.KeyboardActions
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
@@ -19,7 +16,6 @@ import androidx.compose.material3.Icon
|
|||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.LocalMinimumInteractiveComponentSize
|
import androidx.compose.material3.LocalMinimumInteractiveComponentSize
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.SuggestionChip
|
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.CompositionLocalProvider
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
@@ -36,14 +32,12 @@ import androidx.compose.ui.focus.onFocusChanged
|
|||||||
import androidx.compose.ui.graphics.SolidColor
|
import androidx.compose.ui.graphics.SolidColor
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.TextLayoutResult
|
import androidx.compose.ui.text.TextLayoutResult
|
||||||
import androidx.compose.ui.text.TextRange
|
|
||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
import androidx.compose.ui.text.input.ImeAction
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
import androidx.compose.ui.text.input.TextFieldValue
|
import androidx.compose.ui.text.input.TextFieldValue
|
||||||
import androidx.compose.ui.text.style.TextDecoration
|
import androidx.compose.ui.text.style.TextDecoration
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.fabledsword.inkwell.R
|
import com.fabledsword.inkwell.R
|
||||||
import com.fabledsword.inkwell.core.Label
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The note's body, as fields and checkboxes rather than as markup.
|
* The note's body, as fields and checkboxes rather than as markup.
|
||||||
@@ -56,8 +50,6 @@ fun BlockBody(
|
|||||||
blocks: List<EditorBlock>,
|
blocks: List<EditorBlock>,
|
||||||
readOnly: Boolean,
|
readOnly: Boolean,
|
||||||
focus: Long?,
|
focus: Long?,
|
||||||
/** Every tag there is, offered while a `#tag` is typed (see [TagSuggestions]). */
|
|
||||||
tags: List<Label>,
|
|
||||||
onChange: (List<EditorBlock>) -> Unit,
|
onChange: (List<EditorBlock>) -> Unit,
|
||||||
onFocus: (Long?) -> Unit,
|
onFocus: (Long?) -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
@@ -88,7 +80,6 @@ fun BlockBody(
|
|||||||
TaskBlock(
|
TaskBlock(
|
||||||
block = block,
|
block = block,
|
||||||
readOnly = readOnly,
|
readOnly = readOnly,
|
||||||
tags = tags,
|
|
||||||
requester = requester,
|
requester = requester,
|
||||||
onChange = { replace(index, it) },
|
onChange = { replace(index, it) },
|
||||||
onEnter = {
|
onEnter = {
|
||||||
@@ -111,7 +102,6 @@ fun BlockBody(
|
|||||||
ProseBlock(
|
ProseBlock(
|
||||||
block = block,
|
block = block,
|
||||||
readOnly = readOnly,
|
readOnly = readOnly,
|
||||||
tags = tags,
|
|
||||||
requester = requester,
|
requester = requester,
|
||||||
onChange = { replace(index, it) },
|
onChange = { replace(index, it) },
|
||||||
onBlur = {
|
onBlur = {
|
||||||
@@ -142,30 +132,20 @@ fun BlockBody(
|
|||||||
private fun ProseBlock(
|
private fun ProseBlock(
|
||||||
block: EditorBlock,
|
block: EditorBlock,
|
||||||
readOnly: Boolean,
|
readOnly: Boolean,
|
||||||
tags: List<Label>,
|
|
||||||
requester: FocusRequester,
|
requester: FocusRequester,
|
||||||
onChange: (EditorBlock) -> Unit,
|
onChange: (EditorBlock) -> Unit,
|
||||||
onBlur: () -> Unit,
|
onBlur: () -> Unit,
|
||||||
) {
|
) {
|
||||||
var focused by remember { mutableStateOf(false) }
|
BlockField(
|
||||||
Column {
|
value = block.value,
|
||||||
BlockField(
|
onValueChange = { onChange(block.copy(value = it)) },
|
||||||
value = block.value,
|
modifier =
|
||||||
onValueChange = { onChange(block.copy(value = it)) },
|
Modifier
|
||||||
modifier =
|
.focusRequester(requester)
|
||||||
Modifier
|
.onFocusChanged { if (!it.isFocused) onBlur() },
|
||||||
.focusRequester(requester)
|
enabled = !readOnly,
|
||||||
.onFocusChanged {
|
hint = R.string.editor_body_hint,
|
||||||
focused = it.isFocused
|
)
|
||||||
if (!it.isFocused) onBlur()
|
|
||||||
},
|
|
||||||
enabled = !readOnly,
|
|
||||||
hint = R.string.editor_body_hint,
|
|
||||||
)
|
|
||||||
if (focused && !readOnly) {
|
|
||||||
TagSuggestions(value = block.value, tags = tags, onPick = { onChange(block.copy(value = it)) })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -179,13 +159,11 @@ private fun ProseBlock(
|
|||||||
private fun TaskBlock(
|
private fun TaskBlock(
|
||||||
block: EditorBlock,
|
block: EditorBlock,
|
||||||
readOnly: Boolean,
|
readOnly: Boolean,
|
||||||
tags: List<Label>,
|
|
||||||
requester: FocusRequester,
|
requester: FocusRequester,
|
||||||
onChange: (EditorBlock) -> Unit,
|
onChange: (EditorBlock) -> Unit,
|
||||||
onEnter: () -> Unit,
|
onEnter: () -> Unit,
|
||||||
onDelete: () -> Unit,
|
onDelete: () -> Unit,
|
||||||
) {
|
) {
|
||||||
var focused by remember { mutableStateOf(false) }
|
|
||||||
// Material sizes every interactive component to a 48dp touch target, and on a
|
// Material sizes every interactive component to a 48dp touch target, and on a
|
||||||
// checklist that IS the row height.
|
// checklist that IS the row height.
|
||||||
CompositionLocalProvider(LocalMinimumInteractiveComponentSize provides ROW_TOUCH) {
|
CompositionLocalProvider(LocalMinimumInteractiveComponentSize provides ROW_TOUCH) {
|
||||||
@@ -198,11 +176,7 @@ private fun TaskBlock(
|
|||||||
BlockField(
|
BlockField(
|
||||||
value = block.value,
|
value = block.value,
|
||||||
onValueChange = { onChange(block.copy(value = it)) },
|
onValueChange = { onChange(block.copy(value = it)) },
|
||||||
modifier =
|
modifier = Modifier.weight(1f).focusRequester(requester),
|
||||||
Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.focusRequester(requester)
|
|
||||||
.onFocusChanged { focused = it.isFocused },
|
|
||||||
enabled = !readOnly,
|
enabled = !readOnly,
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
textStyle =
|
textStyle =
|
||||||
@@ -224,57 +198,6 @@ private fun TaskBlock(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (focused && !readOnly) {
|
|
||||||
// Indented past the box, so the row reads as belonging to this item's text.
|
|
||||||
TagSuggestions(
|
|
||||||
value = block.value,
|
|
||||||
tags = tags,
|
|
||||||
onPick = { onChange(block.copy(value = it)) },
|
|
||||||
modifier = Modifier.padding(start = ROW_TOUCH),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The existing tags that finish the `#tag` the caret is in, as a row of chips under
|
|
||||||
* the field; nothing when the caret is not in a tag or no tag fits.
|
|
||||||
*
|
|
||||||
* So a note is filed under `#groceries` rather than a new `#grocery` beside it. Which
|
|
||||||
* text counts as a tag being typed, which tags are offered and how one is put in are
|
|
||||||
* in TagSuggest.kt, where they are tested; this is only the row. A tap swaps the token
|
|
||||||
* for the whole name and a space, and leaves the caret after it to keep typing.
|
|
||||||
*
|
|
||||||
* A row rather than a dropdown, because a popup over the field would sit on the very
|
|
||||||
* line being typed, and on a phone the keyboard already owns the bottom of the screen.
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
private fun TagSuggestions(
|
|
||||||
value: TextFieldValue,
|
|
||||||
tags: List<Label>,
|
|
||||||
onPick: (TextFieldValue) -> Unit,
|
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
) {
|
|
||||||
val caret = value.selection.end
|
|
||||||
val at = if (value.selection.collapsed) tagQueryAt(value.text, caret) else null
|
|
||||||
val matches =
|
|
||||||
remember(at?.query, tags) {
|
|
||||||
at?.let { suggestTags(tags, it.query, { t -> t.name }, { t -> t.count ?: 0L }) }.orEmpty()
|
|
||||||
}
|
|
||||||
if (at == null || matches.isEmpty()) return
|
|
||||||
Row(
|
|
||||||
modifier = modifier.fillMaxWidth().horizontalScroll(rememberScrollState()),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
|
||||||
) {
|
|
||||||
matches.forEach { tag ->
|
|
||||||
SuggestionChip(
|
|
||||||
onClick = {
|
|
||||||
val (text, end) = insertTag(value.text, at, tag.name)
|
|
||||||
onPick(TextFieldValue(text, TextRange(end)))
|
|
||||||
},
|
|
||||||
label = { Text("#${tag.name}") },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -258,7 +258,6 @@ fun BoardScreen(
|
|||||||
onNoteAction = onCardAction,
|
onNoteAction = onCardAction,
|
||||||
onConfirmDelete = { confirmingDelete = it },
|
onConfirmDelete = { confirmingDelete = it },
|
||||||
reorderable = state.reorderable,
|
reorderable = state.reorderable,
|
||||||
marksArchived = state.marksArchived,
|
|
||||||
onReorder = onReorder,
|
onReorder = onReorder,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -541,8 +540,6 @@ private fun NoteBoard(
|
|||||||
onConfirmDelete: (Note) -> Unit,
|
onConfirmDelete: (Note) -> Unit,
|
||||||
/** Whether cards can be dragged into a new order: the plain main board only. */
|
/** Whether cards can be dragged into a new order: the plain main board only. */
|
||||||
reorderable: Boolean,
|
reorderable: Boolean,
|
||||||
/** Whether an archived card carries the Archived chip (BoardState.marksArchived). */
|
|
||||||
marksArchived: Boolean,
|
|
||||||
onReorder: (List<String>) -> Unit,
|
onReorder: (List<String>) -> Unit,
|
||||||
) {
|
) {
|
||||||
// The web's breakpoints (NoteGrid.vue: three columns from `lg`, 1024px, four from
|
// The web's breakpoints (NoteGrid.vue: three columns from `lg`, 1024px, four from
|
||||||
@@ -638,7 +635,6 @@ private fun NoteBoard(
|
|||||||
onAction = { onNoteAction(note, it) },
|
onAction = { onNoteAction(note, it) },
|
||||||
onConfirmDelete = { onConfirmDelete(note) },
|
onConfirmDelete = { onConfirmDelete(note) },
|
||||||
dragging = carried,
|
dragging = carried,
|
||||||
marksArchived = marksArchived,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
DisposableEffect(note.id) { onDispose { bounds.forget(note.id) } }
|
DisposableEffect(note.id) { onDispose { bounds.forget(note.id) } }
|
||||||
|
|||||||
@@ -91,14 +91,6 @@ data class BoardState(
|
|||||||
* filtered subset, whose order would be renumbered against notes it can't see.
|
* filtered subset, whose order would be renumbered against notes it can't see.
|
||||||
*/
|
*/
|
||||||
val reorderable: Boolean get() = filterable && filters.count == 0 && !searching
|
val reorderable: Boolean get() = filterable && filters.count == 0 && !searching
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether an archived card says so: anywhere the Archive is not the whole view. A
|
|
||||||
* search or a tag looks through the Archive as well as the board, so finished
|
|
||||||
* work can still be looked up, and the chip is what keeps it from reading as
|
|
||||||
* current.
|
|
||||||
*/
|
|
||||||
val marksArchived: Boolean get() = destination != Destination.Archive
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -191,18 +183,15 @@ class BoardViewModel(
|
|||||||
): List<Note> {
|
): List<Note> {
|
||||||
// Only the main board has filters; every board view takes the search text.
|
// Only the main board has filters; every board view takes the search text.
|
||||||
val searchOnly = BoardFilters().facets(text)
|
val searchOnly = BoardFilters().facets(text)
|
||||||
// A search or a tag looks through the Archive too, as on the web; Archive and
|
|
||||||
// Trash keep a search inside themselves.
|
|
||||||
val notesView = if (text.isNotBlank() || filters.labelIds.isNotEmpty()) VIEW_ALL else VIEW_NOTES
|
|
||||||
return when (destination) {
|
return when (destination) {
|
||||||
Destination.Notes -> core.listNotes(query(notesView, facets = filters.facets(text)))
|
Destination.Notes -> core.listNotes(query(VIEW_NOTES, facets = filters.facets(text)))
|
||||||
Destination.Archive -> core.listNotes(query(VIEW_ARCHIVE, facets = searchOnly))
|
Destination.Archive -> core.listNotes(query(VIEW_ARCHIVE, facets = searchOnly))
|
||||||
Destination.Trash -> core.listNotes(query(VIEW_TRASH, facets = searchOnly))
|
Destination.Trash -> core.listNotes(query(VIEW_TRASH, facets = searchOnly))
|
||||||
// Not a board view: the core models reminders as its own query, since
|
// Not a board view: the core models reminders as its own query, since
|
||||||
// "has a reminder" cuts across archived and active alike. `search` moves
|
// "has a reminder" cuts across archived and active alike. `search` moves
|
||||||
// a search off this view, so it never has text to apply.
|
// a search off this view, so it never has text to apply.
|
||||||
Destination.Reminders -> core.reminderNotes()
|
Destination.Reminders -> core.reminderNotes()
|
||||||
is Destination.WithLabel -> core.listNotes(query(VIEW_ALL, labelId = destination.id, facets = searchOnly))
|
is Destination.WithLabel -> core.listNotes(query(VIEW_NOTES, labelId = destination.id, facets = searchOnly))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -658,9 +647,6 @@ class BoardViewModel(
|
|||||||
private const val VIEW_ARCHIVE = "archived"
|
private const val VIEW_ARCHIVE = "archived"
|
||||||
private const val VIEW_TRASH = "trash"
|
private const val VIEW_TRASH = "trash"
|
||||||
|
|
||||||
/** The board and the Archive together — everything not in Trash. */
|
|
||||||
private const val VIEW_ALL = "all"
|
|
||||||
|
|
||||||
fun factory(
|
fun factory(
|
||||||
core: Inkwell,
|
core: Inkwell,
|
||||||
readFile: (Uri) -> PickedFile,
|
readFile: (Uri) -> PickedFile,
|
||||||
|
|||||||
@@ -55,8 +55,6 @@ fun NoteCard(
|
|||||||
onConfirmDelete: () -> Unit,
|
onConfirmDelete: () -> Unit,
|
||||||
/** The board is carrying this card (BoardDrag.kt). */
|
/** The board is carrying this card (BoardDrag.kt). */
|
||||||
dragging: Boolean = false,
|
dragging: Boolean = false,
|
||||||
/** Whether an archived note says so — everywhere but the Archive itself. */
|
|
||||||
marksArchived: Boolean = true,
|
|
||||||
) {
|
) {
|
||||||
val dark = isSystemInDarkTheme()
|
val dark = isSystemInDarkTheme()
|
||||||
val haptics = LocalHapticFeedback.current
|
val haptics = LocalHapticFeedback.current
|
||||||
@@ -109,11 +107,7 @@ fun NoteCard(
|
|||||||
.border(1.dp, if (dark) CARD_EDGE_DARK else CARD_EDGE_LIGHT, RoundedCornerShape(CARD_RADIUS))
|
.border(1.dp, if (dark) CARD_EDGE_DARK else CARD_EDGE_LIGHT, RoundedCornerShape(CARD_RADIUS))
|
||||||
.padding(12.dp),
|
.padding(12.dp),
|
||||||
) {
|
) {
|
||||||
CardContents(
|
CardContents(note = note, onToggleItem = onToggleItem)
|
||||||
note = note,
|
|
||||||
onToggleItem = onToggleItem,
|
|
||||||
archivedChip = marksArchived && note.archived && !note.trashed,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NoteMenu(
|
NoteMenu(
|
||||||
@@ -126,23 +120,12 @@ fun NoteCard(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** What a card shows, top to bottom: tags, body, links, attachments, reminder, sharing. */
|
||||||
* What a card shows, top to bottom: archived or not, tags, body, links, attachments,
|
|
||||||
* reminder, sharing.
|
|
||||||
*/
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun CardContents(
|
private fun CardContents(
|
||||||
note: Note,
|
note: Note,
|
||||||
onToggleItem: (Int, Boolean) -> Unit,
|
onToggleItem: (Int, Boolean) -> Unit,
|
||||||
archivedChip: Boolean,
|
|
||||||
) {
|
) {
|
||||||
// Above everything, tags included: whether a note is put away is the first thing
|
|
||||||
// to know about a search result or a tag's note, before what it says.
|
|
||||||
if (archivedChip) {
|
|
||||||
TintChip(stringResource(R.string.card_archived), "default")
|
|
||||||
Spacer(Modifier.height(8.dp))
|
|
||||||
}
|
|
||||||
|
|
||||||
// TAGS FIRST, on a row of their own above the body: a board is scanned, and
|
// TAGS FIRST, on a row of their own above the body: a board is scanned, and
|
||||||
// what a note is about should be the first thing the eye lands on. Not beside
|
// what a note is about should be the first thing the eye lands on. Not beside
|
||||||
// the body, whose first line is the note's name.
|
// the body, whose first line is the note's name.
|
||||||
|
|||||||
@@ -243,7 +243,6 @@ fun NoteEditorScreen(
|
|||||||
blocks = blocks,
|
blocks = blocks,
|
||||||
readOnly = readOnly,
|
readOnly = readOnly,
|
||||||
focus = focus,
|
focus = focus,
|
||||||
tags = labels,
|
|
||||||
onChange = { blocks = it },
|
onChange = { blocks = it },
|
||||||
onFocus = { focus = it },
|
onFocus = { focus = it },
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,96 +0,0 @@
|
|||||||
package com.fabledsword.inkwell.ui
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Suggesting existing tags while a `#tag` is typed, so a note is filed under
|
|
||||||
* `#groceries` rather than a new `#grocery` beside it.
|
|
||||||
*
|
|
||||||
* The same rules as the web's `frontend/src/notes/tags.ts` (`tagQueryAt`,
|
|
||||||
* `suggestTags`, `insertTag`), and the same body-tag grammar as `line_tags` in
|
|
||||||
* core/src/local/derive.rs: a `#` at the start or after whitespace, a letter, then
|
|
||||||
* letters, digits, `_` and `-`.
|
|
||||||
*/
|
|
||||||
|
|
||||||
private val TAG_CHAR = Regex("[\\p{IsAlphabetic}\\p{N}_-]")
|
|
||||||
private val WHOLE_TAG = Regex("^\\p{IsAlphabetic}[\\p{IsAlphabetic}\\p{N}_-]*$")
|
|
||||||
|
|
||||||
private fun Char.isTagChar() = TAG_CHAR.matches(toString())
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The `#tag` the caret is in the middle of typing: where its `#` is, where the token
|
|
||||||
* ends (it may run on past the caret), and the part typed so far.
|
|
||||||
*/
|
|
||||||
data class TagQuery(
|
|
||||||
val start: Int,
|
|
||||||
val end: Int,
|
|
||||||
val query: String,
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The tag being typed at [caret], or null when the caret is not in one.
|
|
||||||
*
|
|
||||||
* A bare `#` counts, with an empty query: that is the moment a suggestion list is most
|
|
||||||
* use, because it is the moment someone has not yet decided what to type. Anything
|
|
||||||
* the grammar would not derive (`a#b`, `#2024`, `##x`) is not a tag here either, so
|
|
||||||
* the row never offers to finish something the core would ignore.
|
|
||||||
*/
|
|
||||||
fun tagQueryAt(
|
|
||||||
text: String,
|
|
||||||
caret: Int,
|
|
||||||
): TagQuery? {
|
|
||||||
if (caret < 0 || caret > text.length) return null
|
|
||||||
var i = caret
|
|
||||||
while (i > 0 && text[i - 1].isTagChar()) i--
|
|
||||||
if (i == 0 || text[i - 1] != '#') return null
|
|
||||||
val hash = i - 1
|
|
||||||
if (hash > 0 && !text[hash - 1].isWhitespace()) return null
|
|
||||||
val query = text.substring(i, caret)
|
|
||||||
if (query.isNotEmpty() && !Character.isAlphabetic(query[0].code)) return null
|
|
||||||
var end = caret
|
|
||||||
while (end < text.length && text[end].isTagChar()) end++
|
|
||||||
return TagQuery(start = hash, end = end, query = query)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The existing tags worth offering for [query], best first.
|
|
||||||
*
|
|
||||||
* Names that start with what was typed come before names that merely contain it;
|
|
||||||
* within each, the tag on the most notes first. A tag already typed out in full is
|
|
||||||
* left out, so there is nothing to offer once `#grocery` is finished. A tag whose
|
|
||||||
* name the body grammar can't hold (one made in the picker as "to do") is left out
|
|
||||||
* too: inserting `#to do` would derive `#to`.
|
|
||||||
*/
|
|
||||||
fun <T> suggestTags(
|
|
||||||
tags: List<T>,
|
|
||||||
query: String,
|
|
||||||
name: (T) -> String,
|
|
||||||
count: (T) -> Long,
|
|
||||||
limit: Int = SUGGESTION_LIMIT,
|
|
||||||
): List<T> {
|
|
||||||
val q = foldTag(query)
|
|
||||||
val prefix = { t: T -> if (foldTag(name(t)).startsWith(q)) 0 else 1 }
|
|
||||||
return tags
|
|
||||||
.filter { t ->
|
|
||||||
val f = foldTag(name(t))
|
|
||||||
WHOLE_TAG.matches(name(t)) && f != q && f.contains(q)
|
|
||||||
}.sortedWith(
|
|
||||||
compareBy<T> { prefix(it) }
|
|
||||||
.thenByDescending { count(it) }
|
|
||||||
.thenBy { name(it) },
|
|
||||||
).take(limit)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* [text] with the tag at [at] replaced by `#name`, and where the caret goes after it.
|
|
||||||
* A space follows unless one is already there, so typing simply continues.
|
|
||||||
*/
|
|
||||||
fun insertTag(
|
|
||||||
text: String,
|
|
||||||
at: TagQuery,
|
|
||||||
name: String,
|
|
||||||
): Pair<String, Int> {
|
|
||||||
val after = text.substring(at.end)
|
|
||||||
val insertion = "#$name" + if (after.firstOrNull()?.isWhitespace() == true) "" else " "
|
|
||||||
return (text.substring(0, at.start) + insertion + after) to (at.start + insertion.length)
|
|
||||||
}
|
|
||||||
|
|
||||||
private const val SUGGESTION_LIMIT = 8
|
|
||||||
@@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
<!-- Board -->
|
<!-- Board -->
|
||||||
<string name="board_empty_note">Empty note</string>
|
<string name="board_empty_note">Empty note</string>
|
||||||
<string name="card_archived">Archived</string>
|
|
||||||
|
|
||||||
<!-- The long-press menu. Its ITEMS are the editor_* strings, deliberately: a
|
<!-- The long-press menu. Its ITEMS are the editor_* strings, deliberately: a
|
||||||
note has one vocabulary of things you can do to it, and a board that said
|
note has one vocabulary of things you can do to it, and a board that said
|
||||||
|
|||||||
@@ -1,79 +0,0 @@
|
|||||||
package com.fabledsword.inkwell.ui
|
|
||||||
|
|
||||||
import org.junit.Assert.assertEquals
|
|
||||||
import org.junit.Assert.assertFalse
|
|
||||||
import org.junit.Assert.assertNull
|
|
||||||
import org.junit.Test
|
|
||||||
|
|
||||||
/** The same cases as `frontend/src/notes/tags.test.ts`. */
|
|
||||||
class TagSuggestTest {
|
|
||||||
private data class Tag(
|
|
||||||
val name: String,
|
|
||||||
val count: Long,
|
|
||||||
)
|
|
||||||
|
|
||||||
private val tags =
|
|
||||||
listOf(
|
|
||||||
Tag("grocery", 3),
|
|
||||||
Tag("groceries", 9),
|
|
||||||
Tag("hungry", 1),
|
|
||||||
Tag("to do", 50),
|
|
||||||
Tag("Café", 2),
|
|
||||||
)
|
|
||||||
|
|
||||||
private fun suggest(query: String) = suggestTags(tags, query, { it.name }, { it.count }).map { it.name }
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `the tag being typed is found at the caret, with what has been typed so far`() {
|
|
||||||
assertEquals(TagQuery(start = 9, end = 13, query = "gro"), tagQueryAt("buy milk #gro", 13))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `a bare hash counts at the start or after a space`() {
|
|
||||||
assertEquals(TagQuery(0, 1, ""), tagQueryAt("#", 1))
|
|
||||||
assertEquals(TagQuery(5, 6, ""), tagQueryAt("milk #", 6))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `the tag runs on past the caret to the end of the word`() {
|
|
||||||
assertEquals(TagQuery(0, 8, "gr"), tagQueryAt("#grocery list", 3))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `it is not a tag where the grammar says it is not`() {
|
|
||||||
assertNull(tagQueryAt("a#b", 3)) // no space before the #
|
|
||||||
assertNull(tagQueryAt("#2024", 5)) // starts with a digit
|
|
||||||
assertNull(tagQueryAt("##x", 3))
|
|
||||||
assertNull(tagQueryAt("# heading", 9)) // a space ends it
|
|
||||||
assertNull(tagQueryAt("plain words", 5))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `names that start with the query come first, busiest first`() {
|
|
||||||
assertEquals(listOf("groceries", "grocery", "hungry"), suggest("gr"))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `matching ignores case`() {
|
|
||||||
assertEquals(listOf("Café"), suggest("CAF"))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `a tag already typed in full, and names the body can't hold, are left out`() {
|
|
||||||
assertEquals(emptyList<String>(), suggest("grocery"))
|
|
||||||
assertFalse("to do" in suggest(""))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `a picked tag replaces the whole token and leaves the caret after a space`() {
|
|
||||||
val text = "buy #gr milk"
|
|
||||||
val at = tagQueryAt(text, 7)!!
|
|
||||||
assertEquals("buy #groceries milk" to 14, insertTag(text, at, "groceries"))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `a picked tag at the end of the text gets a space after it`() {
|
|
||||||
val at = tagQueryAt("#gr", 3)!!
|
|
||||||
assertEquals("#grocery " to 9, insertTag("#gr", at, "grocery"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -355,9 +355,6 @@ pub fn list_notes(conn: &Connection, q: &ListQuery) -> rusqlite::Result<Vec<Note
|
|||||||
// without turning up in their Trash, where they could do nothing with it.
|
// without turning up in their Trash, where they could do nothing with it.
|
||||||
"trash" => "trashed = 1 AND permission = 'owner'",
|
"trash" => "trashed = 1 AND permission = 'owner'",
|
||||||
"archived" => "trashed = 0 AND archived = 1",
|
"archived" => "trashed = 0 AND archived = 1",
|
||||||
// The board and the Archive together: what a search or a tag looks through,
|
|
||||||
// so finished work stays findable after it has been put away.
|
|
||||||
"all" => "trashed = 0",
|
|
||||||
_ => "trashed = 0 AND archived = 0",
|
_ => "trashed = 0 AND archived = 0",
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1498,11 +1495,6 @@ mod tests {
|
|||||||
ids(&list(&conn, json!({"view": "trash"}))),
|
ids(&list(&conn, json!({"view": "trash"}))),
|
||||||
vec![trashed.id.as_str()]
|
vec![trashed.id.as_str()]
|
||||||
);
|
);
|
||||||
let mut all = ids(&list(&conn, json!({"view": "all"})));
|
|
||||||
all.sort();
|
|
||||||
let mut expected = vec![kept.id.as_str(), archived.id.as_str()];
|
|
||||||
expected.sort();
|
|
||||||
assert_eq!(all, expected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -52,10 +52,6 @@ const sharedLine = computed(() => {
|
|||||||
return props.note.shared ? "Shared" : "";
|
return props.note.shared ? "Shared" : "";
|
||||||
});
|
});
|
||||||
|
|
||||||
// A search or a tag reaches into the Archive, so an archived card met anywhere but
|
|
||||||
// the Archive itself says so: put away, not current.
|
|
||||||
const showArchived = computed(() => props.note.archived && !props.note.trashed && notes.view !== "archived");
|
|
||||||
|
|
||||||
// --- Retention countdown, so someone browsing Trash can restore a note in time.
|
// --- Retention countdown, so someone browsing Trash can restore a note in time.
|
||||||
// Null when not trashed or retention is off. ---
|
// Null when not trashed or retention is off. ---
|
||||||
const trashDays = computed(() =>
|
const trashDays = computed(() =>
|
||||||
@@ -221,14 +217,6 @@ const tagColors = computed<Record<string, string>>(() => {
|
|||||||
<!-- Tags first: a board is scanned, and tags say what a note is about. Above the
|
<!-- Tags first: a board is scanned, and tags say what a note is about. Above the
|
||||||
body rather than beside it, so they don't compete with its first line, the
|
body rather than beside it, so they don't compete with its first line, the
|
||||||
note's name. -->
|
note's name. -->
|
||||||
<div v-if="showArchived" class="mb-2">
|
|
||||||
<span
|
|
||||||
class="inline-flex items-center gap-1 rounded-full bg-black/5 px-2 py-0.5 text-xs font-medium text-neutral-600 dark:bg-white/10 dark:text-neutral-300"
|
|
||||||
>
|
|
||||||
<Icon name="archive" class="!h-3 !w-3" />
|
|
||||||
Archived
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div v-if="chipLabels.length" class="mb-2 flex flex-wrap gap-1">
|
<div v-if="chipLabels.length" class="mb-2 flex flex-wrap gap-1">
|
||||||
<!-- Every chip carries the `#`, so a lifted chip reads as the `#todo` somebody
|
<!-- Every chip carries the `#`, so a lifted chip reads as the `#todo` somebody
|
||||||
typed, as on Android. -->
|
typed, as on Android. -->
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ import { ref } from "vue";
|
|||||||
import { repo } from "../adapters";
|
import { repo } from "../adapters";
|
||||||
import { useUiStore } from "./ui";
|
import { useUiStore } from "./ui";
|
||||||
|
|
||||||
// `all` is the board and the Archive together: what a search or a tag looks through,
|
export type NoteView = "active" | "archived" | "trash";
|
||||||
// so finished work stays findable after it has been put away. Never Trash.
|
|
||||||
export type NoteView = "active" | "archived" | "trash" | "all";
|
|
||||||
// Combinable facet filters for the board (mirrors the GET /api/notes query). All
|
// Combinable facet filters for the board (mirrors the GET /api/notes query). All
|
||||||
// optional; empty = the plain, unfiltered board. The date bounds are Timeline's.
|
// optional; empty = the plain, unfiltered board. The date bounds are Timeline's.
|
||||||
export interface NoteFacets {
|
export interface NoteFacets {
|
||||||
@@ -120,13 +118,7 @@ export const useNotesStore = defineStore("notes", () => {
|
|||||||
function belongsHere(n: Note): boolean {
|
function belongsHere(n: Note): boolean {
|
||||||
const v = view.value;
|
const v = view.value;
|
||||||
const inView =
|
const inView =
|
||||||
v === "trash"
|
v === "trash" ? n.trashed : v === "archived" ? !n.trashed && n.archived : !n.trashed && !n.archived;
|
||||||
? n.trashed
|
|
||||||
: v === "archived"
|
|
||||||
? !n.trashed && n.archived
|
|
||||||
: v === "all"
|
|
||||||
? !n.trashed
|
|
||||||
: !n.trashed && !n.archived;
|
|
||||||
if (!inView) return false;
|
if (!inView) return false;
|
||||||
if (activeFacets.value.shared === "with_me" && (n.permission ?? "owner") === "owner") return false;
|
if (activeFacets.value.shared === "with_me" && (n.permission ?? "owner") === "owner") return false;
|
||||||
if (activeLabel.value) return n.labels.some((lb) => lb.id === activeLabel.value);
|
if (activeLabel.value) return n.labels.some((lb) => lb.id === activeLabel.value);
|
||||||
|
|||||||
@@ -53,25 +53,20 @@ async function openFromQuery(id: string) {
|
|||||||
void router.replace({ query: q });
|
void router.replace({ query: q });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Facet filters live in the URL query on the board route (a filtered board = a lens).
|
|
||||||
const facets = computed(() => facetsFromQuery(route.query));
|
|
||||||
const facetKey = computed(() => JSON.stringify(facetsToQuery(facets.value))); // stable; ignores ?open=
|
|
||||||
const filtered = computed(() => route.name === "board" && facetCount(facets.value) > 0);
|
|
||||||
|
|
||||||
// A search or a tag looks through the Archive as well as the board, so finished work
|
|
||||||
// can still be looked up; each archived card says so. Archive and Trash keep a search
|
|
||||||
// inside themselves.
|
|
||||||
function viewForRoute(name: unknown): NoteView {
|
function viewForRoute(name: unknown): NoteView {
|
||||||
if (name === "archive") return "archived";
|
if (name === "archive") return "archived";
|
||||||
if (name === "trash") return "trash";
|
if (name === "trash") return "trash";
|
||||||
if (name === "label") return "all";
|
return "active"; // board + label views
|
||||||
const f = facets.value;
|
|
||||||
return name === "board" && (f.q || f.label?.length) ? "all" : "active";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentView = computed<NoteView>(() => viewForRoute(route.name));
|
const currentView = computed<NoteView>(() => viewForRoute(route.name));
|
||||||
const currentLabel = computed<string | null>(() => (route.name === "label" ? String(route.params.id) : null));
|
const currentLabel = computed<string | null>(() => (route.name === "label" ? String(route.params.id) : null));
|
||||||
|
|
||||||
|
// Facet filters live in the URL query on the board route (a filtered board = a lens).
|
||||||
|
const facets = computed(() => facetsFromQuery(route.query));
|
||||||
|
const facetKey = computed(() => JSON.stringify(facetsToQuery(facets.value))); // stable; ignores ?open=
|
||||||
|
const filtered = computed(() => route.name === "board" && facetCount(facets.value) > 0);
|
||||||
|
|
||||||
// Quick-add + pinned/others split only on the main board (not archive/trash/label).
|
// Quick-add + pinned/others split only on the main board (not archive/trash/label).
|
||||||
const isMainBoard = computed(() => route.name === "board");
|
const isMainBoard = computed(() => route.name === "board");
|
||||||
const pinnedNotes = computed(() => notes.items.filter((n) => n.pinned));
|
const pinnedNotes = computed(() => notes.items.filter((n) => n.pinned));
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
ALLOWED_IMAGE_MIMES = {"image/png": ".png", "image/jpeg": ".jpg", "image/gif": ".gif", "image/webp": ".webp"}
|
ALLOWED_IMAGE_MIMES = {"image/png": ".png", "image/jpeg": ".jpg", "image/gif": ".gif", "image/webp": ".webp"}
|
||||||
|
|
||||||
VALID_FILTERS = {"active", "archived", "trash", "all"}
|
VALID_FILTERS = {"active", "archived", "trash"}
|
||||||
|
|
||||||
DISPLAY_TITLE_CAP = 200
|
DISPLAY_TITLE_CAP = 200
|
||||||
|
|
||||||
@@ -72,14 +72,9 @@ def apply_filter(stmt, filter_name: str, archived):
|
|||||||
|
|
||||||
Every branch excludes purge tombstones — content-less rows kept only so the sync
|
Every branch excludes purge tombstones — content-less rows kept only so the sync
|
||||||
feed can tell offline clients a note is gone (see `retention.purge_note`). The
|
feed can tell offline clients a note is gone (see `retention.purge_note`). The
|
||||||
active/archived/all branches get that for free from `deleted_at IS NULL`, since
|
active/archived branches get that for free from `deleted_at IS NULL`, since a
|
||||||
a tombstone keeps the timestamp; Trash is the one view that has to say so.
|
tombstone keeps the timestamp; Trash is the one view that has to say so.
|
||||||
|
|
||||||
`all` is the board and the Archive together: what a search or a tag looks
|
|
||||||
through, so finished work stays findable after it has been put away.
|
|
||||||
"""
|
"""
|
||||||
if filter_name == "all":
|
|
||||||
return stmt.where(Note.deleted_at.is_(None))
|
|
||||||
if filter_name == "archived":
|
if filter_name == "archived":
|
||||||
return stmt.where(Note.deleted_at.is_(None), archived.is_(True))
|
return stmt.where(Note.deleted_at.is_(None), archived.is_(True))
|
||||||
if filter_name == "trash":
|
if filter_name == "trash":
|
||||||
|
|||||||
@@ -1673,21 +1673,6 @@ async def test_owner_and_recipient_each_pin_archive_and_order_their_own(app_clie
|
|||||||
assert await _board_ids(app_client) == [nid, older]
|
assert await _board_ids(app_client) == [nid, older]
|
||||||
|
|
||||||
|
|
||||||
async def test_search_and_tags_look_through_the_archive_but_not_the_trash(app_client, db):
|
|
||||||
kept = await _owners_note(app_client, "ferry times #travel")
|
|
||||||
archived = await _owners_note(app_client, "ferry booked last summer #travel")
|
|
||||||
trashed = await _owners_note(app_client, "ferry refund #travel")
|
|
||||||
await app_client.patch(f"/api/notes/{archived}", json={"archived": True})
|
|
||||||
await app_client.post(f"/api/notes/{trashed}/trash")
|
|
||||||
labels = (await (await app_client.get("/api/labels")).get_json())["labels"]
|
|
||||||
travel = next(lb["id"] for lb in labels if lb["name"] == "travel")
|
|
||||||
|
|
||||||
# The board alone still keeps the archive out of the way.
|
|
||||||
assert await _board_ids(app_client, "q=ferry") == [kept]
|
|
||||||
assert sorted(await _board_ids(app_client, "filter=all&q=ferry")) == sorted([kept, archived])
|
|
||||||
assert sorted(await _board_ids(app_client, f"filter=all&label={travel}")) == sorted([kept, archived])
|
|
||||||
|
|
||||||
|
|
||||||
async def test_unsharing_trashing_and_deleting_each_end_access(app_client, db):
|
async def test_unsharing_trashing_and_deleting_each_end_access(app_client, db):
|
||||||
recipient, _, people = await _three_people(app_client)
|
recipient, _, people = await _three_people(app_client)
|
||||||
nid = await _owners_note(app_client)
|
nid = await _owners_note(app_client)
|
||||||
|
|||||||
Reference in New Issue
Block a user