Skip to content

Commit 0d12fad

Browse files
committed
Merge remote-tracking branch 'tsoding/master'
2 parents d87ec3b + 57d23fa commit 0d12fad

File tree

15 files changed

+529
-38
lines changed

15 files changed

+529
-38
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66

77
jobs:
88
build-linux-gcc:
9-
runs-on: ubuntu-20.04
9+
runs-on: ubuntu-22.04
1010
steps:
1111
- uses: actions/checkout@v1
1212
- name: install dependencies
@@ -19,7 +19,7 @@ jobs:
1919
env:
2020
CC: gcc
2121
build-linux-clang:
22-
runs-on: ubuntu-20.04
22+
runs-on: ubuntu-22.04
2323
steps:
2424
- uses: actions/checkout@v1
2525
- name: install dependencies

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
I have very limited resources in terms of handling feedback on my projects, sorry. So here are the limitations to keep in mind:
2+
3+
- I don't look into reported Issues.
4+
- I only look into small PRs that suggest
5+
- bug fixes,
6+
- documentation fixes.
7+
- I do not look into PRs that
8+
- implement new features,
9+
- refactor/cleanup the code.
10+
- What qualifies as a bug, a feature, or refactoring is entirely upon my interpretation.
11+
12+
Sorry for any inconveniences. If you want to stir the project in a particular direction in terms of features feel free to fork it, I don't mind. Just make sure you have fun while developing it! This is like the whole point!

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Dramatic EDitor
22

3-
**THIS SOFTWARE IS UNFINISHED!!!**
3+
**THIS SOFTWARE IS UNFINISHED!!! Don't have any high expectations.**
44

55
# Quick Start
66

@@ -14,7 +14,7 @@
1414

1515
```console
1616
$ ./build.sh
17-
$ ./ded src\main.c
17+
$ ./ded src/main.c
1818
```
1919

2020
## Windows MSVC
@@ -25,6 +25,7 @@ $ ./ded src\main.c
2525
> .\ded.exe src\main.c
2626
```
2727

28-
# Font
28+
# Fonts
2929

30-
Victor Mono: https://rubjo.github.io/victor-mono/
30+
- Victor Mono: https://rubjo.github.io/victor-mono/
31+
- Iosevka: https://github.com/be5invis/Iosevka

build_msys2_mingw64.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
set -xe
4+
5+
PKGS="--static sdl2 glew freetype2"
6+
CFLAGS="-Wall -Wextra -pedantic -ggdb -DGLEW_STATIC `pkg-config --cflags $PKGS` -Isrc -Dassert(expression)=((void)0) "
7+
LIBS="-lm -lopengl32 `pkg-config --libs $PKGS`"
8+
SRC="src/main.c src/la.c src/editor.c src/file_browser.c src/free_glyph.c src/simple_renderer.c src/common.c"
9+
OBJ=$(echo "$SRC" | sed "s/\.c/\.o/g")
10+
OBJ=$(echo "$OBJ" | sed "s/src\// /g")
11+
12+
# wget "https://raw.githubusercontent.com/tsoding/minirent/master/minirent.h" -P /src
13+
gcc -std=c11 $CFLAGS -c $SRC
14+
# some libs linked with c++ stuff
15+
g++ -o life.exe $OBJ $LIBS $LIBS -static
16+
File renamed without changes.
File renamed without changes.

src/common.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include "common.h"
1818
#define ARENA_IMPLEMENTATION
1919
#include "./arena.h"
20+
#define SV_IMPLEMENTATION
21+
#include "sv.h"
2022

2123
static Arena temporary_arena = {0};
2224

src/common.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define SCREEN_HEIGHT 600
1111
#define FPS 60
1212
#define DELTA_TIME (1.0f / FPS)
13+
#define CURSOR_OFFSET 0.13f
1314

1415
typedef int Errno;
1516

@@ -31,6 +32,16 @@ typedef int Errno;
3132

3233
#define DA_INIT_CAP 256
3334

35+
#define da_last(da) (assert((da)->count > 0), (da)->items[(da)->count - 1])
36+
37+
#define da_move(dst, src) \
38+
do { \
39+
free((dst)->items); \
40+
(dst)->items = (src).items; \
41+
(dst)->count = (src).count; \
42+
(dst)->capacity = (src).capacity; \
43+
} while (0)
44+
3445
#define da_append(da, item) \
3546
do { \
3647
if ((da)->count >= (da)->capacity) { \
@@ -67,6 +78,9 @@ typedef struct {
6778
size_t capacity;
6879
} String_Builder;
6980

81+
#define SB_Fmt "%.*s"
82+
#define SB_Arg(sb) (int) (sb).count, (sb).items
83+
7084
#define sb_append_buf da_append_many
7185
#define sb_append_cstr(sb, cstr) \
7286
do { \
@@ -76,6 +90,8 @@ typedef struct {
7690
} while (0)
7791
#define sb_append_null(sb) da_append_many(sb, "", 1)
7892

93+
#define sb_to_sv(sb) sv_from_parts((sb).items, (sb).count)
94+
7995
typedef struct {
8096
const char **items;
8197
size_t count;

src/editor.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ void editor_delete(Editor *e)
3535
editor_retokenize(e);
3636
}
3737

38+
// TODO: make sure that you always have new line at the end of the file while saving
39+
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
40+
3841
Errno editor_save_as(Editor *e, const char *file_path)
3942
{
4043
printf("Saving as %s...\n", file_path);
@@ -118,6 +121,26 @@ void editor_move_char_right(Editor *e)
118121
if (e->cursor < e->data.count) e->cursor += 1;
119122
}
120123

124+
void editor_move_word_left(Editor *e)
125+
{
126+
while (e->cursor > 0 && !isalnum(e->data.items[e->cursor - 1])) {
127+
e->cursor -= 1;
128+
}
129+
while (e->cursor > 0 && isalnum(e->data.items[e->cursor - 1])) {
130+
e->cursor -= 1;
131+
}
132+
}
133+
134+
void editor_move_word_right(Editor *e)
135+
{
136+
while (e->cursor < e->data.count && !isalnum(e->data.items[e->cursor])) {
137+
e->cursor += 1;
138+
}
139+
while (e->cursor < e->data.count && isalnum(e->data.items[e->cursor])) {
140+
e->cursor += 1;
141+
}
142+
}
143+
121144
void editor_insert_char(Editor *e, char x)
122145
{
123146
editor_insert_buf(e, &x, 1);
@@ -235,7 +258,7 @@ void editor_render(SDL_Window *window, Free_Glyph_Atlas *atlas, Simple_Renderer
235258
}
236259

237260
if (select_begin_chr <= select_end_chr) {
238-
Vec2f select_begin_scr = vec2f(0, -(float)row * FREE_GLYPH_FONT_SIZE);
261+
Vec2f select_begin_scr = vec2f(0, -((float)row + CURSOR_OFFSET) * FREE_GLYPH_FONT_SIZE);
239262
free_glyph_atlas_measure_line_sized(
240263
atlas, editor->data.items + line_chr.begin, select_begin_chr - line_chr.begin,
241264
&select_begin_scr);
@@ -288,7 +311,7 @@ void editor_render(SDL_Window *window, Free_Glyph_Atlas *atlas, Simple_Renderer
288311
size_t cursor_row = editor_cursor_row(editor);
289312
Line line = editor->lines.items[cursor_row];
290313
size_t cursor_col = editor->cursor - line.begin;
291-
cursor_pos.y = -(float) cursor_row * FREE_GLYPH_FONT_SIZE;
314+
cursor_pos.y = -((float)cursor_row + CURSOR_OFFSET) * FREE_GLYPH_FONT_SIZE;
292315
cursor_pos.x = free_glyph_atlas_cursor_pos(
293316
atlas,
294317
editor->data.items + line.begin, line.end - line.begin,

src/editor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ void editor_move_line_up(Editor *e);
5454
void editor_move_line_down(Editor *e);
5555
void editor_move_char_left(Editor *e);
5656
void editor_move_char_right(Editor *e);
57+
void editor_move_word_left(Editor *e);
58+
void editor_move_word_right(Editor *e);
5759
void editor_insert_char(Editor *e, char x);
5860
void editor_insert_buf(Editor *e, char *buf, size_t buf_len);
5961
void editor_retokenize(Editor *e);

0 commit comments

Comments
 (0)