Skip to content

Commit

Permalink
First approach for search dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
c3er committed Jun 19, 2023
1 parent 5243435 commit f507609
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 1 deletion.
35 changes: 35 additions & 0 deletions app/css/screen.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
:root {
--element-dark-bgcolor: #292a2d;
--status-bar-height: 20px;
--std-border-color: #ccc;
--std-border-width: 1px;
--text-dark-color: #f8f8f2;
}

#status-bar {
Expand Down Expand Up @@ -71,6 +73,34 @@
display: table-cell;
}

.dialog-input-field {
margin: 1em 0;
width: 100%;
}

#search-input {
width: 100%;
}

.dialog-buttons {
display: flex;
gap: 10px;
justify-content: flex-end;
}

.dialog-buttons button {
height: 2em;
min-width: 70px;
}

dialog {
width: 80%;
}

input {
box-sizing: border-box;
}

#content {
display: flex;
position: fixed;
Expand Down Expand Up @@ -201,4 +231,9 @@
.toc-expand-button:hover {
background-color: #777;
}

dialog, input {
background-color: var(--element-dark-bgcolor);
color: var(--text-dark-color)
}
}
14 changes: 14 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@
<script src="index.js"></script>
</head>
<body>
<!-- Based on https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog?retiredLocale=de -->
<dialog id="search-dialog">
<form>
<div class="dialog-input-field">
<label for="search-input">Search:</label>
<input id="search-input" type="text" />
</div>
<div class="dialog-buttons">
<button id="search-ok-button" value="default">OK</button>
<button value="cancel" formmethod="dialog">Cancel</button>
</div>
</form>
</dialog>

<div id="menu-border"></div>

<div id="blocked-content-info" hidden="true">
Expand Down
8 changes: 8 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const log = require("./lib/log/log")
const navigation = require("./lib/navigation/navigationRenderer")
const rawText = require("./lib/rawText/rawTextRenderer")
const renderer = require("./lib/renderer/common")
const search = require("./lib/renderer/search")
const toc = require("./lib/toc/tocRenderer")

const TITLE = "Markdown Viewer"
Expand Down Expand Up @@ -142,6 +143,7 @@ function handleDOMContentLoadedEvent() {
contentBlocking.init(document, window)
rawText.init(document, window, updateStatusBar)
navigation.init(document)
search.init(document, handleSearch)

// Based on https://davidwalsh.name/detect-system-theme-preference-change-using-javascript
const match = matchMedia("(prefers-color-scheme: dark)")
Expand All @@ -151,6 +153,10 @@ function handleDOMContentLoadedEvent() {
ipc.send(ipc.messages.finishLoad)
}

function handleSearch(value) {
console.log(value)
}

function handleContextMenuEvent(event) {
event.preventDefault()

Expand Down Expand Up @@ -343,3 +349,5 @@ ipc.listen(ipc.messages.print, () => {

scrollTo(scrollPosition)
})

ipc.listen(ipc.messages.find, () => search.showDialog())
1 change: 1 addition & 0 deletions app/lib/ipc/ipcShared.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ exports.messages = {
resetContentBlocking: "reset-content-blocking",
restorePosition: "restore-position",
updateToc: "update-toc",
search: "search",
unblockAll: "unblock-all",
unblockURL: "unblock-url",
viewRawText: "view-raw-text",
Expand Down
18 changes: 18 additions & 0 deletions app/lib/renderer/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
let _document
let _searchDialog

exports.init = (document, callback) => {
_document = document

_searchDialog = _document.getElementById("search-dialog")
_searchDialog.addEventListener("close", () => callback(_searchDialog.returnValue))

const okButton = _document.getElementById("search-ok-button")
const searchInputElement = _document.getElementById("search-input")
okButton.addEventListener("click", event => {
event.preventDefault()
_searchDialog.close(searchInputElement.value)
})
}

exports.showDialog = () => _searchDialog.showModal()
11 changes: 10 additions & 1 deletion app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,16 @@ function createMainMenu() {
},
{
label: "&Edit",
submenu: [{ role: "copy" }],
submenu: [
{ role: "copy" },
{
label: "Find...",
accelerator: "CmdOrCtrl+F",
click() {
ipc.send(ipc.messages.search)
},
},
],
},
{
label: "&View",
Expand Down

0 comments on commit f507609

Please sign in to comment.