When we transitioned from 'char' based fields to 'int'
proper initial cursor positioning (highlight) was lost
in the 'fields_utility' function. The highlight should
appear on the current sort field. Instead, however, it
was often positioned on the first field listed or some
completely different field other than that sort field.
So this patch will restore the master branch behavior.
[ and on the assumption that a sort field is visible ]
[ we will search first for a field with the 'on' bit ]
Reference(s):
. Mar, 2022 - trade 'char' for 'int'
commit
46aa96e438435628810b33d20cb1c14dc33dd84f
Signed-off-by: Jim Warner <james.warner@comcast.net>
#endif
#define swapEM { int c; unSCRL; c = w->rc.fieldscur[i]; \
w->rc.fieldscur[i] = *p; *p = c; p = &w->rc.fieldscur[i]; }
- #define spewFI { int *t; f = w->rc.sortindx; t = msch(w->rc.fieldscur, f + FLD_OFFSET, EU_MAXPFLGS); \
- if (!t) t = msch(w->rc.fieldscur, (f + FLD_OFFSET) | 0x01, EU_MAXPFLGS); \
+ #define spewFI { int *t; f = w->rc.sortindx; t = msch(w->rc.fieldscur, ENUcvt(f, ENUon), EU_MAXPFLGS); \
+ if (!t) t = msch(w->rc.fieldscur, ENUcvt(f, ENUoff), EU_MAXPFLGS); \
i = (t) ? (int)(t - w->rc.fieldscur) : 0; }
WIN_t *w = Curwin; // avoid gcc bloat with a local copy
const char *h = NULL;
#define FLDviz(q,i) ( (q)->rc.fieldscur[i] & 0x01 )
#define ENUviz(w,E) ( NULL != msch((w)->procflgs, E, w->maxpflgs) )
#define ENUpos(w,E) ( (int)(msch((w)->pflgsall, E, (w)->totpflgs) - (w)->pflgsall) )
+#define ENUcvt(E,x) ( (int)(((E + FLD_OFFSET) << 1) | x) )
+#define ENUon 0x01
+#define ENUoff 0x00
// Support for variable width columns (and potentially scrolling too)
#define VARcol(E) (-1 == Fieldstab[E].width)